0
我有一个if语句在cakePHP应用程序,我无法弄清楚为什么它没有做我期望的。如果声明不输出预期结果
public function isAuthorized($user) {
if ($user['role'] === 'admin'){
return true;
}
if ((in_array($this->action, array('view', 'index')))&&($user['role'] === 'senior' || 'junior')) {
return true;
}
return false;
}
我想如果有一个用户与角色“代理”它会拒绝所有的行动。
如果我使用这个,而不是everthing玫瑰色,只是不知道为什么它没有检查两个参数之前将布尔值设置为True?
public function isAuthorized($user) {
if ($user['role'] === 'admin'){
return true;
}
if ($user['role'] == 'agent'){
return false;
}
if (in_array($this->action, array('edit', 'add', 'delete'))) {
if ($user['role'] == 'senior' || 'junior') {
return false;
}
}
return true;
}
任何想法? 谢谢