我希望在登录操作中根据通过url传递的参数执行不同的语句。在appController中,我有一个这样的代码:
function beforeFilter() {
if(isset($this->passedArgs['type']) && ($this->passedArgs['type'] == 1)) {
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login', 'type' => 1);
} elseif(isset($this->passedArgs['type']) && ($this->passedArgs['type'] == 2)) {
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login', 'type' => 2);
} else {
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login', 'type' => 1);
}
$this->Auth->loginRedirect = array('controller' => 'customers', 'action' => 'index');
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
}
但是,当我传递参数时我无法登录,因为var_dump($ this-> data)是空数组。当我删除参数时它工作得很好。请有人告诉我这是否是将参数传递给动作的正确方法?
答案 0 :(得分:0)
您应该在login()操作中处理。
有关登录操作的示例,请参阅此https://github.com/CakeDC/users/blob/2.0/Controller/UsersController.php#L336
如果用户成功登录,请检查传递的args以查找您要查找的内容,并根据该值进行重定向。