0
我无法遵循cakephp blog authorization教程。显示下面的代码,但由于它没有很好的评论,我不确定这些参数究竟是什么。cakephp授权数组参数
我有一个iteminfo动作的项目控制器,我只想让特定项目的创建者能够查看。它是通过以下网址,其中数字是itemnumber访问和iteminfo是动作
/items/iteminfo/3
例如
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);
}
我试图修改它只是这个
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('iteminfo'))) {
print_r($this->request->params); //attempting to view the params array
}
return parent::isAuthorized($user);
}
我只是想查看params数组,所以我知道在我的iteminfo操作中要修改什么。有什么办法可以查看吗?基本上我想看看数组的组成部分是什么,所以我知道要引用什么。
这里是项目表。
itemid userid itemname itemcost datecreated
嗯,我猜混乱的一部分还在于isAuthorized是如何被调用。它是CakePHP的一部分,如果声明了该函数,它将一直被检查,还是必须从我的iteminfo控制器调用它? – user2268281 2013-04-29 03:29:23
@ user2268281 yes isAuthorized是AppController的一部分,它是Cake的Auth组件的一部分,您可以在cakephp doc的auth组件中查看详细信息.. – 2013-04-29 04:13:12