Hello,

i am trying the IBM tutorial no 2 and have a problem, when using the
function $aro->create(...) in my register action.
After clicking the "register" button, I get an Error 404. If I comment
out the $aro->create() the redirect is successful.
Here's the code:

class UsersController extends AppController
{
        var $components = array('Acl');

        function register() {

                $this->set('username_error', 'Username must be between 6 and 40
characters.');
                if(!empty($this->data)){
                        if($this->User->validates($this->data)){
                                
if($this->User->findByUsername($this->data['User']['username'])) {
                                        $this->User->invalidate('username');
                                        $this->set('username_error', 'User 
already exists.');
                                } else {
                                        $this->data['User']['password'] = 
md5($this->data['User']
['password']);
                                        $this->data['User']['last_login'] = 
date("Y-m-d H:i:s");
                                        if($this->User->save($this->data)){
                                                $aro = new Aro();
                                                //$user_id = 
$this->User->getLastInsertID();
                                                $aro->create($this->User->id, 
'Users', $this->data['User']
['username']);
                                                $this->Session->write('user', 
$this->data['User']['username']);
                                                
$this->Session->write('last_login', 'You are logged in first
time');
                                                $this->redirect('/users/index');
                                        } else {
                                                $this->flash('There was a 
problem saving this information', '/
users/register');
                                        }

                                }
                        } else {
                                $this->User->validateErrors($this->User);
                        }
                }
        }

        function knownusers() {

                $this->set('knownusers', $this->User->findAll(null, array('id',
'username', 'first_name', 'last_name', 'last_login'), 'id DESC'));
        }

        function login(){

                $this->set('error', false);
                if($this->data){
                        $results = 
$this->User->findByUsername($this->data['User']
['username']);
                        if($results && $results['User']['password'] == 
md5($this-
>data['User']['password'])){
                                $this->Session->write('user', 
$this->data['User']['username']);
                                $this->Session->write('last_login', 
$results['User']
['last_login']);
                                $results['User']['last_login'] = date("Y-m-d 
H:i:s");
                                $this->User->save($results);
                                $this->redirect('/users/index');
                        } else {
                                $this->set('error', true);
                        }
                }
        }

        function logout() {

                $this->Session->delete('user');
                $this->Session->delete('last_login');
                $this->redirect('/users/login');
        }

        function index() {

                $username = $this->Session->read('user');
                if($username){
                        $results = $this->User->findByUsername($username);
                        $this->set('User', $results['User']);
                        $this->set('last_login', 
$this->Session->read('last_login'));
                } else {
                        $this->redirect('/users/login');
                }
        }
}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to