I have this in my services.php:
$di->set('dispatcher', function () {
//Create/Get an EventManager
$eventsManager = new \Phalcon\Events\Manager();
//Attach a listener
$eventsManager->attach("dispatch", function ($event, $dispatcher, $exception) {
//controller or action doesn't exist
if ($event->getType() == 'beforeException') {
switch ($exception->getCode()) {
case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(array(
'controller' => 'index',
'action' => 'notFound'
));
return false;
}
}
});
$dispatcher = new \Phalcon\Mvc\Dispatcher();
//Set default namespace to backend module
$dispatcher->setDefaultNamespace("Vokuro\Controllers");
//Bind the EventsManager to the dispatcher
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
});
```php
and this in my routes.php:
```php
<?php
$router = new Phalcon\Mvc\Router(false);
$router->add('/', array(
'controller' => 'index',
'action' => 'index'
));
$router->add('/login', array(
'controller' => 'session',
'action' => 'login'
));
$router->add('/registration', array(
'controller' => 'session',
'action' => 'signup'
));
return $router;
i have set Phalcon\Mvc\Router(false);
to false, because I don't want session/login to be accessible, only /login for SEO purposes. It works great, however, the notfound redirect in the dispatcher in services.php is not forwarding the user to the IndexController and notFoundAction , but instead he is taken to the IndexController and IndexAction.
I have tried to add notFound in the routes like this:
<?php
$router = new Phalcon\Mvc\Router(false);
$router->notFound(array(
'controller' => 'index',
'action' => 'notFound'
));
$router->add('/', array(
'controller' => 'index',
'action' => 'index'
));
$router->add('/login', array(
'controller' => 'session',
'action' => 'login'
));
$router->add('/registration', array(
'controller' => 'session',
'action' => 'signup'
));
return $router;
Now the /login
and /registration
works, but the homepage is redirected to the notFoundAction, which is wrong. the homepage should be /
. Why is that? What should I change to allow homepage to work?