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

Phalcon Router same url

Is it posible to have same router with different controller and action?

example

    $router->add('/:params', array(
        'module' => 'frontend',
        'controller' => 'center',
        'action' => 'page',
        'params' => 1,
    ));

    $router->add('/:params', array(
        'module' => 'frontend',
        'controller' => 'page',
        'action' => 'view',
        'params' => 1,
    ));

It will use the first one it encounters when matching routes, so one of them will be discarded.

I can't imagine what practical use there would be for having 2 routes with the same pattern.

This is the case my client want same url for the page and center

example: https://mysite/center-slugs - this is for center https://mysite/page-slugs - this is for page..



3.1k
Accepted
answer
edited Aug '15

basicaly we did a dirty hack to make this happend thank you for the reply...

public function pageAction($slugs){

    if(page != null){
        execute page
    }
    else{
         //execute center
         $this->centerAction($slugs);
         //redirect view to center view
         $this->view->pagelayout = 'center';
         $this->view->pick("center/view");
    }

}

fucntion centerAction($slugs){
    //code for center call
}