We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Routing cannot correctly route to action

I tried to set up router according to https://docs.phalcon.io/en/latest/reference/routing.html The router can successfully route to the controller, but no matter what action I specify, it always goes to the index action of the controller.

Can somebody help me?

edited Feb '16

Can you paste your routes? We can not tell you what's the problem without viewing your route definitions code.

edited Feb '16

Codes are here. I copied the router from the vokuro example, and added my own one. However, the first two don't even work.

routes.php

<?php /*

  • Define custom routes. File gets included in the router service definition. */ $router = new Phalcon\Mvc\Router();

$router->add("/confirm/{code}/{email}", array( "controller" => "account", "action" => "confirmEmail" ));

$router->add("/reset-password/{code}/{email}", array( "controller" => "account", "action" => "resetPassword" ));

$router->add("/manage/:object/:method/:params", array( "controller" => "manage", "action" => 1, "method" => 2, "params" => 3 ));

return $router;

services.php

/

  • Dispatcher use a default namespace, and show 404 when not found */ $di->set( 'dispatcher', function () use($di) { $evManager = $di->getShared('eventsManager');

    $evManager->attach(
        "dispatch:beforeException",
        function($event, $dispatcher, $exception)
        {
            switch ($exception->getCode()) {
                case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                    $dispatcher->forward(
                        array(
                            'controller' => 'error',
                            'action'     => 'show404',
                        )
                    );
                    return false;
            }
        }
    );
    $dispatcher = new Dispatcher();
    $dispatcher->setDefaultNamespace('Geohome_web\Controllers');
    $dispatcher->setEventsManager($evManager);
    return $dispatcher;

    } );

/*

  • Loading routes from the routes.php file */

$di->set('router', function () { return require DIR . '/routes.php'; });