look guys!
$di->set('dispatcher', function() use ($di) {
$eventsManager = $di->getShared('eventsManager');
$eventsManager->attach('dispatch:beforeDispatch',function (Event $event, Dispatcher $dispatcher){
$plugin = new Plugin();
$security = new SecurityPlugin();
$auth = $plugin->session->get('auth');
if (!$auth){
$role = 'Guests';
} else {
$role = 'Users';
}
$controller = $dispatcher->getControllerName();
$action = $dispatcher->getActionName();
$acl = $security->getAcl();
echo (!$acl->isRole($dispatcher->getControllerName())) ? "true<br>" : "false";
//$allowed = $acl->isAllowed($role, $controller, $action);
if (!$acl->isRole($dispatcher->getControllerName())) {
$dispatcher->forward(array(
'controller' => 'errors',
'action' => 'show404'
));
//header("index.php?_url=errors/show404");
return false;
}
});
$eventsManager->attach('dispatch:beforeException',function(Event $event, Dispatcher $dispatcher,$exception){
switch($exception->getCode()){
case PhDispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case PhDispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(array(
'controller' => 'errors',
'action' => 'show500'
));
return false;
}
});
$dispatch = new PhDispatcher();
$dispatch->setEventsManager($eventsManager);
return $dispatch;
});
my problem in this code and that is showing this message, and I've tried everything I have no more idea someone could help me? My ACL is this way:
public function getAcl(){
//throw new \Exception("something");
if (!isset($this->persistent->acl)) {
$acl = new AclList();
$acl->setDefaultAction(Acl::DENY);
$roles = array(
'users' => new Role('Users'),
'guests' => new Role('Guests')
);
foreach ($roles as $role) {
$acl->addRole($role);
}
//Private area resources
/*$privateResources = array(
'companies' => array('index', 'search', 'new', 'edit', 'save', 'create', 'delete'),
'products' => array('index', 'search', 'new', 'edit', 'save', 'create', 'delete'),
'producttypes' => array('index', 'search', 'new', 'edit', 'save', 'create', 'delete'),
'invoices' => array('index', 'profile')
);
foreach ($privateResources as $resource => $actions) {
$acl->addResource(new Resource($resource), $actions);
}*/
//Public area resources
$publicResources = array(
'index' => array('index'),
'errors' => array('show404', 'show500','show401')/*,
'about' => array('index'),
'register' => array('index'),
'session' => array('index', 'register', 'start', 'end'),
'contact' => array('index', 'send')*/
);
foreach ($publicResources as $resource => $actions) {
$acl->addResource(new Resource($resource), $actions);
}
foreach ($roles as $role) {
foreach ($publicResources as $resource => $actions) {
foreach ($actions as $action){
$acl->allow($role->getName(), $resource, $action);
}
}
}
/*foreach ($privateResources as $resource => $actions) {
foreach ($actions as $action){
$acl->allow('Users', $resource, $action);
}
}*/
$this->persistent->acl = $acl;
}
return $this->persistent->acl;
}