Hi Tomasz,
As I know there are no official way ;)
I did it in this way, it is only simple example checking if session admin is set
index.php
$di->set("dispatcher", function() {
$eventManager = new \Phalcon\Events\Manager();
$eventManager->attach("dispatch:beforeException", function($event, $dispatcher, $exception) {
if($exception instanceof \Phalcon\Mvc\Dispatcher\Exception) {
$dispatcher->forward(array(
"controller" => "index",
"action" => "index"
));
return false;
}
});
$dispatcher = new \Phalcon\Mvc\Dispatcher();
$dispatcher->setEventsManager($eventManager);
return $dispatcher;
});
Base Controller
class ControllerBase extends Phalcon\Mvc\Controller
{
public function onConstruct() //this constructor/initializator is executed even if action isn't exist, you could handle your filter here
{
if($this->session->get("admin")!==1)
{
$this->request->redirect("login/index");
}
}
public function initialize()
{
}
}
IndexController
class IndexController extends ControllerBase //i use it for every controller
{
public function indexAction()
{
}
}
LoginController
class LoginController extends \Phalcon\Mvc\Controller //i use it when no admin
{
public function indexAction()
{
}
}