Hola buenas...estoy intentando separar mi aplicacion por modulos pero parece ser que hay algo de mala configuracion con los path, creo, me sale el siguiente error.
Resource 'default:default' not found
La estructua es la siguiente.
1 . Default
1.1 Control,
1.1.1 Auth. Aqui es donde hago el login.
Código PHP:
class Default_AuthController extends Zend_Controller_Action
{
public function loginAction()
{
if(Zend_Auth::getInstance()->hasIdentity())
{
$this->_redirect('auth/login');
}
$request = $this->getRequest();
$form = new Form_Login();
if($request->isPost())
{
if($form->isValid($this->_request->getPost()))
{
$authAdapter = $this->getAuthAdapter();
$username = $form->getValue('username');
$password = $form->getValue('password');
$authAdapter->setTableName('usuarios')
->setIdentity($username)
->setCredential($password);
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
if($result->isValid())
{
$identity = $authAdapter->getResultRowObject(array('user','role'));
$authStorage = $auth->getStorage();
$authStorage->write($identity);
if($identity->role=='invitado')
$_redirect = $this->_redirect('listados/index');
else
$_redirect = $this->_redirect('visitas/index');
}
else {
$this->view->errorMessage = "User wrong";
}
}
}
$this->view->form = $form;
}
}
1.2 models
1.2.1 Acl ; Aqui estan mis permisos.
Código PHP:
class Model_Acl extends Zend_Acl
{
public function __construct(Zend_Auth $auth) {
$this->addRole(new Zend_Acl_Role('guest'));
$this->addRole(new Zend_Acl_Role('invitado'));
$this->addRole(new Zend_Acl_Role('usuario','invitado'));
$this->addRole(new Zend_Acl_Role('admin'),'usuario');
$this->add(new Zend_Acl_Resource('default'));
$this->add(new Zend_Acl_Resource('default:auth','login'));
$this->add(new Zend_Acl_Resource('default:index','default'));
$this->add(new Zend_Acl_Resource('default:error','default'));
$this->add(new Zend_Acl_Resource('admin'));
$this->add(new Zend_Acl_Resource('admin:visitas','admin'));
$this->add(new Zend_Acl_Resource('admin:index','admin'));
$this->add(new Zend_Acl_Resource('listado'));
$this->add(new Zend_Acl_Resource('listado:listados','listado'));
$this->allow('invitado','default:auth','login');
$this->allow('invitado','default:auth','login');
$this->allow('invitado','default:error','error');
$this->deny('usuario','default:auth','login');
$this->allow('usuario','default:auth','logout');
$this->allow('usuario','default:index','index');
$this->allow('usuario','listado:listados',array('index','listado'));
$this->allow('usuario','admin:visitas',array('index','add','update'));
$this->allow('admin','admin:visitas',array('index','add','update','delete'));
}
}
2.Admin
3.Listado
En mi Bootstrap. tengo.
Código PHP:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
private $_auth;
private $_acl;
protected function _initAutoload()
{
$modelLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH . '/modules/default',
)
);
if(Zend_Auth::getInstance()->hasIdentity())
Zend_Registry::set('role',Zend_Auth::getInstance()->getStorage()->read()->role);
else
Zend_Registry::set('role','guest');
$this->_auth = Zend_Auth::getInstance();
$this->_acl = new Model_Acl($this->_auth);
$controller = Zend_Controller_Front::getInstance();
$controller->registerPlugin(new My_Plugins_AccessCheck($this->_acl,Zend_Registry::get('role')));
return $modelLoader;
}
protected function _initViewHelpers()
{
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$navContainerConfig = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml','nav');
$navContainer = new Zend_Navigation($navContainerConfig);
$view->navigation($navContainer)->setAcl($this->_acl)->setRole(Zend_Registry::get('role'));
}
Y tengo una carpeta con mis plugins en Public que es la siguiente estructura.
1 . Library
1.1 MY
1.1.1Plugins
- Accesscheck.php que es el siguiente.
Código PHP:
class My_Plugins_AccessCheck extends Zend_Controller_Plugin_Abstract
{
private $_acl = null;
private $_auth = null;
public function __construct($acl,$auth) {
$this->_acl = $acl;
$this->_auth = $auth;
}
public function preDispatch(Zend_Controller_Request_Abstract $request){
$module = $request->getModuleName();
$resource = $request->getControllerName();
$module = $request->getModuleName();
if( $this->_acl->has( $this->getRequest()->getActionName() ) )
$resource = $this->getRequest()->getActionName();
elseif( $this->_acl->has( $this->getRequest()->getControllerName() ) )
$resource = $this->getRequest()->getControllerName();
elseif( $this->_acl->has( $this->getRequest()->getModuleName() ) )
$resource = $this->getRequest()->getModuleName();
if ( !$this->_acl->isAllowed(Zend_Registry::get('role'),$module.':'. $resource) && $role == 'guest' )
{
$request->setModuleName('default');
$request->setControllerName('auth');
}
elseif (!$this->_acl->isAllowed(Zend_Registry::get('role'),$module.':'. $resource) )
{
$request->setModuleName('default');
$request->setControllerName('error');
$request->setActionName('error');
}
}
}
Y mi menu navigation esta en application, configs. navigation.xml
Código:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<nav>
<logout>
<label>Logout</label>
<module>default</module>
<controller>auth</controller>
<action>logout</action>
<resource>default:auth</resource>
<privilege>logout</privilege>
</logout>
<login>
<label>Login</label>
<module>default</module>
<controller>auth</controller>
<action>login</action>
<resource>default:auth</resource>
<privilege>login</privilege>
</login>
<visitas>
<label>Visitas</label>
<uri>#</uri>
<resource>admin:visitas</resource>
<privilege>index</privilege>
<pages>
<list>
<label>Visitantes</label>
<module>admin</module>
<controller>visitas</controller>
<action>index</action>
</list>
<add>
<label>Add</label>
<module>admin</module>
<controller>visitas</controller>
<action>add</action>
</add>
<update>
<label>Update</label>
<module>admin</module>
<controller>visitas</controller>
<action>update</action>
</update>
<delete>
<label>Delete</label>
<module>admin</module>
<controller>visitas</controller>
<action>delete</action>
</delete>
</pages>
</visitas>
<listados>
<label>Listados</label>
<uri>#</uri>
<resource>listado:listados</resource>
<privilege>index</privilege>
<pages>
<list>
<label>Listado</label>
<module>listado</module>
<controller>listados</controller>
<action>listado</action>
<!--<resource>listados:listado</resource>-->
</list>
</pages>
</listados>
</nav>
</config>
La verdad que llevo probando diferente manera pero se me escapa algo alguien podria decirme que puede ser.
El error sale en el AccesCheck , no se porque sale. Resource 'default:default' not found
Un saludo.