Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP: Call to a member function setFlash() on a non-object

Tags:

php

cakephp

I get the following error when trying to logout of my CakePHP app:

Notice (8): Undefined property: UsersController::$Session [APP/controllers/users_controller.php, line 75] Fatal error: Call to a member function setFlash() on a non-object in /Users/cameron/Sites/cakeapp/app/controllers/users_controller.php on line 75 

This is the code for lines 74, 75 and 76:

function logout() {     $this->Session->setFlash('Good-Bye');     $this->redirect($this->Auth->logout()); } 
like image 479
Cameron Avatar asked Feb 02 '11 16:02

Cameron


1 Answers

It looks like you don't have the Session component loaded in your Users controller.

The Session component should be loaded by default, but if you've set the components array in AppController this will overwrite the defaults.

This means that if you have

var $components = array(); 

in your AppController, make sure the Session component is included there:

var $components = array('Session'); 

Alternatively, you can load the Session component in your Users controller if you don't want to use it app-wide.

like image 151
Mark Northrop Avatar answered Sep 18 '22 18:09

Mark Northrop