Hi,
I'd run into a strange problem while I'm trying to set up an error handler controller.
I have an ErrorController:
namespace Main\Controllers;
class ErrorController extends ControllerBase
{
public function initialize()
{
/* some stuff here */
}
public function indexAction()
{
$code = $this->dispatcher->getParam('code');
switch($code){
case 99: $this->flash->error($this->main_text['error99']); break;
case 404: $this->flash->error($this->main_text['error404']); break;
default: $this->flash->error($this->main_text['error500']);
}
}
}
I have this at the end of my routing:
$router->add('/error/{code:[0-9]+}', array(
'namespace' => 'Main\\Controllers',
'controller' => 'error',
'action' => 'index'
));
When I try to reach f.e. /error/404
, I got the Object not found
error. Same when I try /error/index
, /error/index/404
and Access forbidden
for /error/
. It works only for /error
, then it runs the index action.
I have a forwarding for errors in beforeException event, it also calls this controller and action, but it doesn't work neither for forwarding nor redirecting. I tried to comment this forwarding out, but the result was the same.
$eventsManager->attach("dispatch:beforeException", function($event, $dispatcher, $exception) {
switch ($exception->getCode()) {
case \Phalcon\Mvc\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case \Phalcon\Mvc\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
case \Phalcon\Mvc\Dispatcher::EXCEPTION_INVALID_HANDLER:
case \Phalcon\Mvc\Dispatcher::EXCEPTION_INVALID_PARAMS:
$dispatcher->forward(
array(
'controller' => 'error',
'action' => 'index',
'params' => 404
)
);
return false;
default:
$dispatcher->forward(
array(
'controller' => 'error',
'action' => 'index',
'params' => 500
)
);
return false;
}
});
I have no idea why the routing doesn't work, all other routing patterns works fine, and I don't find other pattern that may conflict with this one. Do I miss some important point?
I still use Phalcon 2.