Thursday, August 26, 2010

Re: Error on adding user with Auth component on

The $components variable has a default value which includes Session.
When you define that variable in your controller you lose this default
value, and Session becomes inaccessible. To be able to access the
session again you have to add it yourself to the component list:

var $components = array ('Session', 'Auth');

On Aug 27, 1:11 am, Chuck <chivalrys...@gmail.com> wrote:
> When I have the Auth component on (component added to
> app_controller.php, login(), logout() and beforeFilter() methods added
> to user_component.php) and I attempt to add a user, the record gets
> added, but I get the following error:
>
> Notice (8): Undefined property: UsersController::$Session [APP/
> controllers/users_controller.php, line 60]
> Fatal error: Call to a member function setFlash() on a non-object in /
> home/mydomain/dev. mydomain.com/app/controllers/users_controller.php
> on line 60
>
> For the most part, this is a plain baked site. Line 60 is in the add
> action of users_controller.php, the line that reads $this->Session->setFlash( __( 'The user has been saved', true ) );. The entire add
>
> action is below, which I believe is simply the action created by bake.
>
> function add() {
>         if ( !empty( $this->data ) ) {
>                 $this->User->create();
>                 if ( $this->User->save( $this->data ) ) {
>                         $this->Session->setFlash( __( 'The user has been saved', true ) );
>                         $this->redirect( array( 'action' => 'index' ) );
>                 } else {
>                         $this->Session->setFlash( __( 'The user could not be saved. Please,
> try again.', true ) );
>                 }
>         }
>         $userTypes = $this->User->UserType->find( 'list' );
>         $this->set( compact( 'userTypes' ) );
>
> }
>
> I only get the error when Auth is enabled. Any suggestions on how to
> fix this would be appreciated.
>
> Thanks,
> Chuck

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: