2010-08-05 84 views
1

任何人都可以解释我的工作Auth->authorize = "actions"
在我的项目中,我正在计划给这个。
由于this授课我会授权给我打电话$this->Aro->check($user,"controllers/:controller/:action")检查权限对组非用户使用Auth-> authorize =“操作”

这样会检查对用户的权利吗?
这意味着用户应该在aros表中。
但我不需要这样来检查用户,但我需要检查一组
我该如何执行此操作。

现在,当用户不在阿罗表它显示

使得阿罗的将是唯一的组和用户添加到阿罗斯需要

thankz提前

回答

1

得到使用该溶液
reference
我延长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'; 
} 

这解决了我的问题:)

0

取看看这个chapter。要检查组权限做到这一点(“模型”和“foreign_key”的值从阿罗斯表):

$this->Acl->check(
    array('model' => 'Group', 'foreign_key' => 2), 
    'controller/action' 
); 
+0

但由于Auth->授权=“行动”中给出的检查将完成全自动吧? – RSK 2010-08-05 18:44:08

+1

没错。您需要使用'$ this-> Auth-> authorize ='controller';'和'isAuthorized()'方法(http://book.cakephp.org/view/396/authorize)。 – bancer 2010-08-05 23:13:17

+0

,但是如果我给'$ this-> Auth-> authorize ='controller';'我需要转到每个控制器并重写'isAuthorized()'。我怎样才能避免在每个控制器这个重写? – RSK 2010-08-07 05:22:21