mam problem w uruchomieniu ACL
mam pliki
index.php
<?php .... include "Zend/Loader.php"; Zend_Loader::loadClass('Zend_Controller_Front'); Zend_Loader::loadClass('Zend_Config_Ini'); Zend_Loader::loadClass('Zend_Registry'); Zend_Loader::loadClass('Zend_Db'); Zend_Loader::loadClass('Zend_Db_Table'); Zend_Loader::loadClass('Zend_Db_Select'); Zend_Loader::loadClass('Zend_Db_Table_Abstract'); Zend_Loader::loadClass('Zend_Auth'); Zend_Loader::loadClass('Zend_Acl'); Zend_Loader::loadClass('MyACL'); // load configuration $config = new Zend_Config_Ini('./application/config.ini','general'); Zend_Registry::set('config', $config); // setup database $db = Zend_Db::factory( $config->db->adapter, $config->db->config->toArray() ); Zend_Db_Table::setDefaultAdapter($db); Zend_Registry::set('db', $db); $db->query('SET NAMES latin2'); $db->query('SET CHARACTER SET latin2'); //setup ACL $acl = new MyACL( $db ); Zend_Registry::set('acl', $acl); ... ?>
MyACL.php
<?php require_once 'Zend/Db.php'; require_once 'Zend/Acl.php'; require_once 'Zend/Acl/Role.php'; require_once 'Zend/Acl/Resource.php'; require_once 'Zend/Acl/Exception.php'; class MyACL extends Zend_ACL { public function __construct( Zend_Db_Adapter_Abstract &$db ){ $auth = Zend_Auth::getInstance(); ->where('u.username = ?',$auth->getIdentity()->username); $result = $select->query()->fetchAll(); $acl = new Zend_Acl(); $acl->addRole(new Zend_Acl_Role($auth->getIdentity()->username)); foreach($result as $acl_role){ $acl->add(new Zend_Acl_Resource($acl_role['resource'])); } foreach($result as $acl_role){ $acl->allow($auth->getIdentity()->username,$acl_role['resource'],unserialize($acl_role['privileges'])); } } } ?>
i w IndexController.php mam funkcje
<?php function preDispatch() { $auth = Zend_Auth::getInstance(); if (!$auth->hasIdentity()) { $this->_redirect('auth/login'); } $acl= Zend_Registry::get('acl'); } ?>
I występuje błąd po autoryzacji jak wchodzę na index:
Fatal error: Uncaught exception 'Zend_Acl_Role_Registry_Exception' with message 'Role 'test' not found' in /var/www/htdocs/projekt4/library/Zend/Acl/Role/Registry.php:123 Stack trace: #0 /var/www/htdocs/projekt4/library/Zend/Acl.php(688): Zend_Acl_Role_Registry->get('test') #1 /var/www/htdocs/projekt4/application/controllers/IndexController.php(29): Zend_Acl->isAllowed('test', 'index', 'read') #2 /var/www/htdocs/projekt4/library/Zend/Controller/Action.php(496): IndexController->preDispatch() #3 /var/www/htdocs/projekt4/library/Zend/Controller/Dispatcher/Standard.php(242): Zend_Controller_Action->dispatch('indexAction') #4 /var/www/htdocs/projekt4/library/Zend/Controller/Front.php(929): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #5 /var/www/htdocs/projekt4/index.php(47): Zend_Controller_Front->dispatch() #6 {main} thrown in /var/www/htdocs/projekt4/library/Zend/Acl/Role/Registry.php on line 123
męczę sie z tym już kilka dni (pewnie dlatego iż jestem początkującym w Zendzie)
Bardzo proszę o pomoc
już rozwiązałem problem. polegał on na tym że chciałem przekazywać przez registry ale używałem _redirect teraz używam sesji i jest ok