【发布时间】:2016-08-22 08:13:22
【问题描述】:
我正在使用 CakePHP 3.2 开发卖家面板。
有sellers 表来存储所有详细信息和凭据,并且有一个整数类型的列status。
status 列用于将卖家标记为已批准或不这样
0 = Registered not approved
1 = Approved
2 = Canceled
ProductsController.php 中有sell 动作。
我想只允许状态为 1 的卖家执行此操作。如果用户未获得批准,则根据状态 ID 打印消息
1 : Sorry! Your account is not verified yet.
2 : Sorry! Your account has been canceled. Contact Admin.
这就是我为防止sell 采取行动而采取的措施。我在ProductsController.php 的beforeFilter() 中添加了以下代码
public function beforeFilter(Event $event)
{
parent::beforeFilter($event);
if ($this->Auth->user('status') != 1) {
$this->Auth->deny(['sell']);
}
}
但这不起作用,所有卖家仍然可以使用sell 操作。
【问题讨论】:
-
试试
$this->Auth->user()['status'] -
不工作@JacekBBudzyñski
-
它应该可以工作 - 你能调试 $this->Auth->user() 吗?
标签: cakephp authorization cakephp-3.2