trying to use $_SESSION['Auth']['User']['id'] in beforefilter()
I'm trying to use $_SESSION['Auth']['User']['id']
in beforefilter()
function in app_controller.php
. But I'm getting error message.
Error message is -> Undefined variable: _SESSION [APP\app_controller.php
Here is my app_controller file. thanks
`class AppController extends Controller {
var $components = ar开发者_开发百科ray('Acl', 'Session', 'Auth');
....................................`
Use $this->Auth->user('id')
, not the $_SESSION
variable.
If you insist on reading from the session directly, use $this->Session->read('Auth.User.id')
.
$_SESSION
should be accessible, but that depends on when the session gets started and whether you're using PHP's session management at all. Use Cake's wrappers, they take care of those details.
精彩评论