php - cakephp3 read session in component -
i have plugin developed cakephp3 inside component read value stored in sessions.
in cakephp 2 used:
$userid = cakesession::read('auth.user.id');
but if use cakephp 3 return me error:
error: call undefined method userpermissions\controller\component\userpermissionscomponent::_hassession() file /users/info/sites/cakephp3/vendor/cakephp/cakephp/src/network/session.php line: 382
to include sessions inside component i'm using :
use cake\network\session;
how can read value in session? thanks
i make happen in initialize()
method such:
use cake\controller\component; use cake\controller\componentregistry; class yourcomponent extends component{ public $controller = null; public $session = null; public function initialize(array $config) { parent::initialize($config); // .... /** * current controller */ $this->controller = $this->_registry->getcontroller(); $this->session = $this->controller->request->session(); // can use $this->session in other methods // if debug = true else use print_r() test debug($this->session->read('auth.user.id')); } }