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;
}
任何想法? 謝謝