douhao123457 2014-10-28 19:27
浏览 58

Cakephp Acl'Aro 0.foreign Key'in'哪里的子句''

I have problem with Acl in cakePhp 2.5.x . I have done everything cakephp cookbook told me, but i still have a problem.

So I set up my application to have 3 groups. Administrator, Manager, and User, just like in cookbook. At this time my app only has 1 user and this user belong to Administrator. Administrator can do anything.

this is my AppController code :

class AppController extends Controller {

public $components = array(
        'Acl',
        'Session',
        'Auth' => array(
            'loginRedirect'  => array(
                'controller' => 'users',
                'action'     => 'index'
                ),
            'logoutRedirect' => array(
                'controller' => 'users',
                'action'     => 'login'
                ),
            'authenticate' => array(
                'Form'      => array(
                        'passwordHasher' => 'Blowfish'
                    )

                ),
            'authorize' => array(
                'Actions' => array('actionPath'=>'controllers'),
                ),

            )
    );

public function beforeFilter(){
    //not thinked yet
    parent::beforeFilter();
    //$this->initDB();
}

public function initDB(){
    $group = $this->User->MemberOf;
    // Allow admins to everything 
    $group->id = 1; 
    $this->Acl->allow($group, 'controllers');

}

}

and UsersController

class UsersController extends AppController{

public $helpers     = array('Html','Form');
public $uses        = array("User","Group");

// callbacks
public function beforeFilter(){
    parent::beforeFilter();

The problem is when i(Administrator, and i've logged in) want to call 'add' action of UsersController cakephp give me this error :

Database Error

Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Aro0.foreignKey' in 'where clause'

SQL Query: SELECT Aro.id, Aro.parent_id, Aro.model, Aro.foreign_key, Aro.alias FROM dotcore.aros AS Aro INNER JOIN dotcore.aros AS Aro0 ON (Aro.lft <= Aro0.lft AND Aro.rght >= Aro0.rght) WHERE Aro0.model = 'Group' AND Aro0.foreignKey = '1' ORDER BY Aro.lft DESC

Notice: If you want to customize this error message, create app\View\Errors\pdo_error.ctp

I know that in aros table there's no foreignKey field, but foreign_key, but why cakephp use foreignKey in where clause?

Please help me to solve this problem, i can't find any post/question about this problem, so i ask this problem here. I really appreciate your response. Thank you

  • 写回答

1条回答 默认 最新

  • dongmiao4733 2014-11-13 10:42
    关注

    Foreign key in aro used to associate with your groups and users table.

    Depending on model column value in aro ,foreign_key treated differently

    example : model = Group : Then the foreign_key is associated with groups table. model = User : Then the foreign_key is associated with users table.

    groups:

    id    name
    1     Administrator
    2     Manager
    3     User
    

    the above column 'id' is treated as a foreign key in aro but mention Model=Group. if Model= 'User' in aro then foreign key will be user id.

    the foreign_key column used to check the permissions by ACL

    Example:

    $this->ACL->check('Group.1',$aco) 
    

    above method check for administrator permission on aco.

    $this->ACL->check('User.1',$aco) 
    

    above method check permission of user whose id is 1 on aco.

    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器