LoginSignup
2
0

More than 5 years have passed since last update.

Phalcon 「Action was not found on handler Controller」の一般的な対応方法

Posted at
$di->set('dispatcher', function () {

    $em = new \Phalcon\Events\Manager();

    $em->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' => 'route404'
                    ));
                    return false;
            }
        }
    });

    $dispatcher = new \Phalcon\Mvc\Dispatcher();
    // Set default namespace
    $dispatcher->setDefaultNamespace("Your\Controllers");

    $dispatcher->setEventsManager($em);

    return $dispatcher;
});
IndexController.php
namespace Your\Controllers;

class IndexController {

    public function route404Action()
    {
    }

}
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0