Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session helper not found in CakePHP

Tags:

cakephp

I'm trying to use CakePHP's session helper, like this inside a controller:

$this->Session->write('cart', $cart);

But it does not work. I get this error:

Fatal error: Call to a member function write() on a non-object in ...

It's enabled in the config file, I added the session helper to the controller and the app controller

like image 853
skerit Avatar asked Aug 01 '26 02:08

skerit


1 Answers

Turns out, you also need to add Session as a component, so AppController looks like this:

class AppController extends Controller {

public $layout = 'website';

public $components = array(
    'Paginator',
    'DebugKit.Toolbar',
    'Session'
);

public $helpers = array(
    'Html',
    'Js' => array('Jquery'),
    'Session'
);

}
like image 106
skerit Avatar answered Aug 03 '26 01:08

skerit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!