CakePHP 在函数之外使用 Session
我有一段代码负责控制器中的分页:
var $paginate = array(
'limit' => 5,
'conditions' => array('Tanque.user_id' => 1),
'order' => array(
'Tanque.nome' => 'asc'
)
);
所以,我有 'Tanque.user_id' =>; 1
,我想使用 user_id
而不是数字 1
。我从会话 $this->Session->read('Auth.User.id')
获取 user_id
,但收到错误。
如何在函数之外使用 $this->Session->read
?
I have a piece of code that is responsible for the pagination in my controllers:
var $paginate = array(
'limit' => 5,
'conditions' => array('Tanque.user_id' => 1),
'order' => array(
'Tanque.nome' => 'asc'
)
);
So, where I have 'Tanque.user_id' => 1
, I would like to use the user_id
instead of the number 1
. I am getting the user_id
from the Session $this->Session->read('Auth.User.id')
, but I get an error.
How can I use the $this->Session->read
outside of the functions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能在类声明中使用表达式,只能使用静态值。更不用说在这个阶段所有组件都还没有加载。在函数中执行此操作,例如
beforeFilter
:You cannot use expressions in class declarations, you can only use static values. Not to mention that all the components aren't even loaded at this stage. Do this in a function, like
beforeFilter
: