Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CakePHP 2.x ACL在工作时遇到问题_Php_Cakephp_Acl - Fatal编程技术网

CakePHP 2.x ACL在工作时遇到问题

CakePHP 2.x ACL在工作时遇到问题,php,cakephp,acl,Php,Cakephp,Acl,我一直在尝试让CakePHP ACL与我的新应用程序一起工作,这让我感到非常痛苦。由于某些原因,ACL似乎不起作用,但是教程是垃圾,没有很好地解释每个组件。e、 g.ACO如何链接到控制器/功能/视图 我已经让ACL正常工作,直到让页面知道是否允许用户查看它,同样的问题还有他们看不见的菜单项 我注意到,如果我将此代码添加到页面中,数组会将组显示为空白: $user = $this->Auth->user(); pr($user); 数组返回: Array ( [id] =

我一直在尝试让CakePHP ACL与我的新应用程序一起工作,这让我感到非常痛苦。由于某些原因,ACL似乎不起作用,但是教程是垃圾,没有很好地解释每个组件。e、 g.ACO如何链接到控制器/功能/视图

我已经让ACL正常工作,直到让页面知道是否允许用户查看它,同样的问题还有他们看不见的菜单项

我注意到,如果我将此代码添加到页面中,数组会将组显示为空白:

$user = $this->Auth->user(); 
pr($user);
数组返回:

Array
(
    [id] => 80
    [first_name] => Bob
    [last_name] => Test
    [email] => email@emial.com
    [username] => TestAdmin
    [tokenhash] => cleared
    [is_active] => 1
    [created] => 2014-10-03 16:32:45
    [modified] => 2014-10-03 16:32:45
    [token_expires_at] => 
    [group_id] => 3
    [Group] => Array
        (
            [id] => 
            [name] => 
            [enabled] => 
            [created] => 
            [modified] => 
        )

)
该网站基本上是一个门户网站,访问者只能登录/注册。用户组都可以访问仪表板,但它会以一个连续的循环结束,除非我允许每个人访问仪表板(我想是因为该组未被识别)

任何帮助都将不胜感激,我知道你可能需要我发布我使用的代码,所以请让我知道你需要什么

提前谢谢

编辑:

我已经更新了我的AppController,如下所示,它已经开始显示阵列中的组,因为它应该如此!!!奇怪的是,谢谢你朝着正确的方向努力

AppController.php

<?php

App::uses('Controller', 'Controller');

class AppController extends Controller {
    public function beforeRender() {
        if((($this->params['controller']==='Users') || ($this->params['controller']==='users'))&&(($this->params['action']=='login') || ($this->params['action']=='register') || ($this->params['action']=='success') || ($this->params['action']=='forgot_password') || ($this->params['action']=='reset_password')) ){
            $this->theme = 'DataHouseLogin';
        }else{
            $this->theme = 'DataHouse';
        }
        parent::beforeRender();
    }

    public $components = array(
        'Acl',
        'RequestHandler',
        'DebugKit.Toolbar' => array('panels' => array('history' => false)),
        'Session',
        'Auth' => array(
            'authorize' => array(
                'Actions' => array(
                    'actionPath' => 'controllers'
                    )
            ), 
            'loginAction' => array(
                'controller' => 'Users', 
                'action' => 'login'
            ),
            'loginRedirect' => array(
                'controller' => 'Dashboard',
                'action' => 'index'
            ),
            'logoutRedirect' => array(
                'controller' => 'Users',
                'action' => 'login'
            ),
            'authError' => 'Did you really think you are allowed to see that?',
            'authenticate' => array(
                'Form' => array(
                    'passwordHasher' => 'Blowfish'
                )
            )
        )
    );

    public function beforeFilter() {
        //$this->Auth->allowedActions = array('display','index','register');
        $this->set('user', $this->Auth->user());    
        $this->set('acl', $this->Acl);
        $this->Auth->authorize = array(
            'Controller',
            'Actions' => array('actionPath' => 'controllers')
        ); 


        parent::beforeFilter();
    }
    public function isAuthorized($user) {
        // Default deny
        return false;
    } 
}

我认为您应该尝试正确配置Auth组件。尝试将此代码放入AppController:

class AppController extends Controller {
 public $components = array('RequestHandler', 'Session',
    'Acl',
    'Auth' => array(
        'authorize' => array(
            'Actions' => array('actionPath' => 'controllers')
        )
    ),
  );  

 public function beforeFilter() {
   $this->Auth->authorize = array(
        'Controller',
        'Actions' => array('actionPath' => 'controllers')
  );    
   $this->Auth->authenticate = array('Form' => array('fields' => array('username' => 'name', 'password' => 'password')));
   $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login', 'admin' => false, 'plugin' => false);
   $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login', 'admin' => false, 'plugin' => false);
 }

 public function isAuthorized($user) {
    // Default deny
    return false;
 } 
}
编辑: 在UserModel和GroupModel中,添加作为属性:

public $actsAs = array('Acl' => array('type' => 'requester'));
在UserModel设置parentNode函数中:

public function parentNode() {
  if (!$this->id && empty($this->data)) {
      return null;
  }
  if (isset($this->data['User']['group_id'])) {
      $groupId = $this->data['User']['group_id'];
  } else {
      $groupId = $this->field('group_id');
  }
  if (!$groupId) {
      return null;
  } else {
      return array('Group' => array('id' => $groupId));
  }
} 

您是否配置了ACL和Auth组件?请向我展示您的AppController->beforeFilter()函数。您好,Grzegorz,我添加了beforeFilter。我已经更改了它,现在无法再登录到AppController。您应该首先正确设置ACL,可以在没有ACL的情况下使用Auth组件,但在这种情况下,您必须手动将授权逻辑放入IsAuthorized函数中。读了这篇文章,你们会更清楚的。嗯,是的,我确实遵循了这一点,在我开始实施ACL之前,一切都很好,然后ACL似乎不适用。好的,我已经设法让数组按照预期拾取组。我的下一个问题是:我如何告诉我的控制器,例如DashboardController,它链接到ACO DashboardController?$this->Auth->authorize=array('controller')完成了这项任务……但还需要设置一些其他内容,最好的解决方案是使用插件-它将帮助您完成这项任务