use*_*124 0 php authentication cakephp cakephp-2.0
我需要CakePHP中的帮助 - 简单身份验证和授权应用程序教程
public function isAuthorized($user) {
// All registered users can add posts
if ($this->action === 'add') {
return true;
}
// The owner of a post can edit and delete it
if (in_array($this->action, array('edit', 'delete'))) {
$postId = $this->request->params['pass'][0];
if ($this->Post->isOwnedBy($postId, $user['id'])) {
return true;
}
}
return parent::isAuthorized($user);
}
Run Code Online (Sandbox Code Playgroud)
这部分我不知道这意味着什么,我已经搜索谷歌但我没有找到
$this->Post->isOwnedBy($postId, $user['id'])
Run Code Online (Sandbox Code Playgroud)
isOwnedBy
是post模型中的一个函数,Post.php
它覆盖AppController's
isAuthorized
函数以了解post是否由该用户发布.如果没有,那么让他去访问add
操作,否则允许访问add
,edit
,delete
阅读本文以获取更多详细信息蛋糕书授权 - 谁允许访问 - 什么