0

アプリケーションの ACL の作成に取り組んでいます。しかし、私はエラーがどこにあるかを見つけることができないようです。これは単純な ACL であるため、ここで問題を見つけるのはそれほど難しくないと思います。次のエラーが表示されます: 致命的なエラー: Zend_Acl_Role_Registry_Exception: Role 'secretaria' が /usr/local/zend/share/ZendFramework/library/Zend/View/Helper/Navigation/HelperAbstract.php の 522 行目に見つかりませんでした。コード(以下)。エラーの場所を見つけるのに役立つ人がいれば、本当に感謝しています。

<?php

class Plugins_acl extends Zend_Controller_Plugin_Abstract{

    //NOME DOS RESOURCES
    //private $modules = array();
    //private $perfils = array();

    public function preDispatch(Zend_Controller_Request_Abstract $request)
       {
        $acl = new Zend_Acl();

                //create the user roles
                //1-ADMINISTRADOR
                //2-MEDICO
                //3- ASSISTENTE
                //4- SECREATRIA
                $acl->addRole(new Zend_Acl_Role('administrador'));
                $acl->addRole(new Zend_Acl_Role('medico'));
                $acl->addRole(new Zend_Acl_Role('assistente'));
                $acl->addRole(new Zend_Acl_Role('secretaria'));
                $acl->addRole(new Zend_Acl_Role('guest'));

                //create the resources
                $acl->addResource(new Zend_Acl_Resource('index'));
                $acl->addResource(new Zend_Acl_Resource('error'));
                $acl->addResource(new Zend_Acl_Resource('dashboard'));
                $acl->addResource(new Zend_Acl_Resource('login'));
                $acl->addResource(new Zend_Acl_Resource('default'));

                $acl->allow(null,'index');
                $acl->allow('secretaria','dashboard');
                $acl->allow('secretaria','index');
                $acl->allow('secretaria','default');
                $acl->allow('guest','login');

                $auth = Zend_Auth::getInstance();
                if($auth->hasIdentity())
                    {
                        $identity = $auth->getIdentity();
                        $role = strtolower($identity['role']);
                    }
                    else
                        {
                            $role = 'guest';
                    }

                        $controller = $request->controller;
                        $action = $request->action;
                        $module= $request->module;

                        if(!$acl->isAllowed($role, $module))
                            {
                                if('guest' == $role)
                                    {
                                            $request->setModuleName('auth');
                                            $request->setControllerName('login');
                                            $request->setActionName('index'); 
                                    }
                                    else
                                        {
                                            $request->setModuleName('error');
                                            $request->setControllerName('error');
                                            $request->setActionName('notauthorized');                                       }
                                    }       

    }
}

ここにナビゲーション用の私のコード

public function _initNavigation ()
{
    $this->acl = Zend_Registry::get('acl');
    $this->bootstrap('layout');
    $this->role = Zend_Auth::getInstance()->getStorage()->read();
    $layout = $this->getResource('layout');
    $view =  $layout->getView();
    $navConfig = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
    $navigation= new Zend_Navigation($navConfig);
    $view->navigation($navigation)->setAcl($this->acl)->setRole($this->role['Role']);
}

この時点での問題は、acl のレジストリが見つからないことです。そのため、ナビゲーションをロードするときに、ロールなどがわからない...

<?php

class Plugins_acl extends Zend_Controller_Plugin_Abstract{

//NOME DOS RESOURCES
//private $modules = array();
//private $perfils = array();

public function preDispatch(Zend_Controller_Request_Abstract $request)
   {
            $acl =new Zend_Acl();       
            //create the user roles
            //1-ADMINISTRADOR
            //2-MEDICO
            //3- ASSISTENTE
            //4- SECREATRIA
            $acl->addRole(new Zend_Acl_Role('administrador'));
            $acl->addRole(new Zend_Acl_Role('medico'));
            $acl->addRole(new Zend_Acl_Role('assistente'));
            $acl->addRole(new Zend_Acl_Role('secretaria'));
            $acl->addRole(new Zend_Acl_Role('guest'));


            //create the resources
            $acl->addResource(new Zend_Acl_Resource('index'));
            $acl->addResource(new Zend_Acl_Resource('error'));
            $acl->addResource(new Zend_Acl_Resource('dashboard'));
            $acl->addResource(new Zend_Acl_Resource('login'));
            $acl->addResource(new Zend_Acl_Resource('default'));

            $acl->allow(null,'index','index');
            $acl->allow('secretaria','dashboard');
            $acl->allow('secretaria','index');
            $acl->allow('secretaria','default');
            $acl->allow('guest','login');

            Zend_Registry::set('Zend_Acl', $acl);

            $auth = Zend_Auth::getInstance();
            $roleUser = Zend_Auth::getInstance()->getStorage()->read();

            Zend_Registry::set('Zend_Acl_Role', $roleUser['Role']);
            if($auth->hasIdentity())
                {
                    $identity = $auth->getIdentity($roleUser['Role']);
                    $role = strtolower($identity['Role']);
                }
                else
                    {
                        $role = 'guest';
                }

                    $controller = $request->controller;
                    $action = $request->action;
                    $module= $request->module;

                    if(!$acl->isAllowed($role, $module))
                        {
                            if('guest' == $role)
                                {
                                        $request->setModuleName('auth');
                                        $request->setControllerName('login');
                                        $request->setActionName('index'); 
                                }
                                else
                                    {
                                        $request->setModuleName('error');
                                        $request->setControllerName('error');
                                        $request->setActionName('notauthorized');                                       }
                                }       
    /*
    $this->modules = $aclNs->resources['modules'];
    $this->perfils = $aclNs->resources['perfils'];
    $this->modules[]= 'default';
    $this->modules[]= 'logout';
    $this->modules[]= 'login';
    $this->modules[]= 'error';
    $this->modules[]= 'index';
    $this->modules[]= 'gerenciar';
    */
}

}

4

2 に答える 2

0

これをレイアウトに追加した後、正常に機能しました。

$this->navigation()->setAcl(Zend_Registry::get('Zend_Acl'));
$this->navigation()->setRole(Zend_Registry::get('Zend_Acl_Role'));
于 2013-07-21T01:12:12.870 に答える