good_evening
good_evening

Reputation: 21739

How to include Session component in the model? CakePHP

I really need to use $this->Session->read('id') in one of the model's method therefore I need to include Session component in the model. How can I do that? public $component = array('Session'); doesn't work like in the Controller.

Upvotes: 1

Views: 2750

Answers (2)

For using session inside the custom component I tried with

public $components = array('Session');

and then called it by using

$this->Session->read('Auth.User.id');

Upvotes: 0

mark
mark

Reputation: 21743

the component should be and is limited to the controller.

but you can use the static access:

CakeSession::read('Auth.User.id')

etc

Upvotes: 6

Related Questions