使用Auth-> =授权“行动”检查的权限组对用户不
-
26-09-2019 - |
题
任何一个可以解释我Auth->authorize = "actions"
结果的工作
在我的项目我计划TP给这个。结果
如此教我在authorize将调用$this->Aro->check($user,"controllers/:controller/:action")
这将检查对用户右键点击?? 也就是说,用户应该有在阿罗斯表。结果 但我不需要这个要检查用户,但我需要检查针对集团 - 如何可以实现这一目标。
现在,当用户不在阿罗表它示出了
,使得阿罗的将只有组和用户的加入到阿罗斯需要
thankz预先
解决方案
得到的溶液,点击
使用此参考结果
我延长AuthComponent到CustomAuth和重写的isAutorized()
方法在AuthComponent如下
在控制器/组件/ custom_auth.php
<?php
App::import('Component','Auth');
class CustomAuthComponent extends AuthComponent {
public function isAuthorized($type = null, $object = null, $user = null) {
$actions = $this->__authType($type);
if( $actions['type'] != 'actions' ){
return parent::isAuthorized($type, $object, $user);
}
if (empty($user) && !$this->user()) {
return false;
} elseif (empty($user)) {
$user = $this->user();
}
$group = array('model' => 'Group','foreign_key' =>$user['Login']['group_id']);
$valid = $this->Acl->check($group, $this->action());
return $valid;
}
}
?>
在app_controller.php
function beforeFilter()
{
$this->CustomAuth->userModel = 'Login';
$this->CustomAuth->allowedActions = array('display');
$this->CustomAuth->actionPath = 'controllers/';
$this->CustomAuth->authorize = 'actions';
}
这解决了我的问题:)
其他提示
看看这个章。要检查组权限做到这一点(“模型”和“foreign_key”的值从阿罗斯表):
$this->Acl->check(
array('model' => 'Group', 'foreign_key' => 2),
'controller/action'
);
不隶属于 StackOverflow