开发者

a member function check() on a non-object

开发者 https://www.devze.com 2023-01-05 07:53 出处:网络
I am using cakePHP 1.26. In a .ctp file, I have a few like of codes like this: $sess = $this->Session->check(\'user\');

I am using cakePHP 1.26. In a .ctp file, I have a few like of codes like this:

$sess = $this->Session->check('user');
if($sess){
// do soe开发者_如何学编程mthing
}
else{
// do soemthing then
}

But I got this error then:

Fatal error: Call to a member function check() on a non-object in /home/vol12/mysite.com/htdocs/app/views/layouts/testing1.ctp on line 10

Can I use the Check method in a .ctp file to check if a session exists?


There is a session component for use in controllers, of course, that is referenced as $this->Session. What you're looking for, I think is the session helper that is available to views. This is referenced simply as $session, IIRC. I wanted to verify that (it's been a while since I had to use it), but can't find it in the docs at the moment. What I think you want is:

$sess = $session->check('user');


I can do this in 1.2.5:

if ($session->read('Auth.User')){ ... }

see the manual: http://book.cakephp.org/view/484/Session which is brief but explicit. Note that you cannot write to the session from the view.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号