我对 CakePHP 相当陌生,我试图只允许那些创建事件的用户能够编辑或删除事件,所以我将当前用户 id 与当前事件的事件的 'user_id' 字段进行比较(在用户创建事件时保存)。任何帮助将不胜感激,我的代码(Andrew Perk)如下:
public function isAuthorized($user) {
$this->loadModel('User');
if ($user['role'] == 'admin') {
return true;
}
if (in_array($this->action, array('edit', 'delete'))) {
if ($user['id'] != $this->request->data['Event']['user_id']) { ///THIS IS THE LINE I FEEL IS WRONG - PLEASE ADVISE
//echo debug($event['user_id']);
//$this->Session->setFlash(__('You are not allowed to edit someones event'));
return false;
}
}
return true;
}