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

Parameters Not Showing in URL

My Custom Routing is as follows:-

$router = new \Phalcon\Mvc\Router(false);

$router->removeExtraSlashes(true);

$router->add( '/:module', array( 'module' => 1, 'controller' => 'index', 'action' => 'index' ) )
->setName("oml");

$router->add( '/:module/:controller', array( 'module' => 1, 'controller' => 2, 'action' => 'index' ) )
->setName("mct");

$router->add( '/:module/:controller/:action', array( 'module' => 1, 'controller' => 2, 'action' => 3 ) )
->setName("mvc");

$router->add( '/:module/:controller/:action/:params', array( 'module' => 1, 'controller' => 2, 'action' => 3, 'params' => 4 ) )
->setName("mvcp");

$router->add( '/', array( 'module' => 'user', 'controller' => 'index', 'action' => 'index' ) );

When I try to get URL using below syntax in volt, It doen't show any parameter in URL and there is value for board.id

url(['for' : 'mvcp', 'module' : 'admin', 'controller' : 'board', 'action' : 'edit', 'id' : board.id])

I also modify dispatcher in DI using below code:-

$eventsManager = new EventsManager();

$eventsManager->attach('dispatch', function($event, $dispatcher) {

    if ($event->getType() == 'beforeDispatchLoop') {

        $keyParams = array();
        $params = $dispatcher->getParams();
        foreach ($params as $number => $value) {

            if ($number & 1) {

                $keyParams[$params[$number - 1]] = $value;
            }
        }
        $dispatcher->setParams($keyParams);
        $dispatcher->setDefaultNamespace(ucfirst($dispatcher->getModuleName())."\Controllers");
    }
});

$dispatcher = new Phalcon\MVc\Dispatcher();
$dispatcher->setEventsManager($eventsManager);

return $dispatcher;

Please help me out.

Sorry if there is some problem with code formatting in this discussion. It's my first question

I've updated your post with proper code formatting. Feel free to edit your post to see what changes I made.

Help Me Out!!!!



17.8k
edited Feb '15
url(['for' : 'mvcp', 'module' : 'admin', 'controller' : 'board', 'action' : 'edit', 'params' : board.id])  

may help

I want module/controller/action/id/1 in URL. rather than module/controller/action/1

Anybody know the answer?

Guys Plz Help Me out! I am stuck in project because of this