Hi,
My app is based on INVO Security and NotFound plugins. I managed to get the ACL in Security to work, but not the NotFound.
Whenever i type https://localhost/somerubbishtext, the NotFound Plugin Exception is not triggered. Instead, the page got redirected to /login/index
Services.php
/**
* The Events Manager
*/
$di->set('dispatcher', function() use ($di) {
$eventsManager = new EventsManager;
/**
* Handle access control list using SecurityPlugin
*/
$eventsManager->attach('dispatch:beforeDispatch', new Security);
/**
* Handle exceptions and not-found exceptions using NotFoundPlugin
*/
$eventsManager->attach('dispatch:beforeException', new NotFound);
$dispatcher = new Dispatcher;
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
});
NotFound.php
public function beforeException(Event $event, MvcDispatcher $dispatcher, Exception $exception)
{
if ($exception instanceof DispatcherException) {
switch ($exception->getCode()) {
case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(array(
'controller' => 'errors',
'action' => 'index'
));
return false;
}
}
$dispatcher->forward(array(
'controller' => 'errors',
'action' => 'index'
));
return false;
}
Security.php
public function beforeDispatch(Event $event, Dispatcher $dispatcher)
{
$auth = $this->session->get('auth');
if (!$auth){
$role = 'Guests';
} else {
$role = 'Users';
}
$controller = $dispatcher->getControllerName();
$action = $dispatcher->getActionName();
$acl = $this->getAcl();
$allowed = $acl->isAllowed($role, $controller, $action);
//var_dump($acl);
//die;
if ($allowed != Acl::ALLOW) {
$dispatcher->forward(array(
'controller' => 'login',
'action' => 'index'
));
return false;
}
}
Expert Advice appreciated!