cakephp $this->params 未在 beforeFilter 中设置
我需要在 AppController::beforeFilter() 中使用 $this->params 做一些事情,但当我设置它时,我得到了 Notice (8): Undefined variable: a
在 beforeFilter()
中,b
变量被正常设置。这是正常行为吗?如果不是,如何在 beforeFilter()
中设置参数?如果我可以在调用任何操作之前使用参数,那就更好了。
function beforeFilter() {
$this->set('a', $this->params);
}
function beforeRender() {
$this->set('b', $this->params);
}
I needed to do something with $this->params in the AppController::beforeFilter()
I get Notice (8): Undefined variable: a
but when I set it in beforeFilter()
the b
variable is set normally. Is this normal behavior? And if it isn't, how do I get the params to be set in beforeFilter()
? It would have been better if I could work with the params before any action is called.
function beforeFilter() {
$this->set('a', $this->params);
}
function beforeRender() {
$this->set('b', $this->params);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
糟糕的是,我在控制器中覆盖了
beforeFilter
,并且忘记在开始时调用parent::beforeFilter()
。现在好了。My bad, I had overriden
beforeFilter
in an controller and forgot to callparent::beforeFilter()
at the start. Now it's ok.