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

How set set custom routes in INVO app?

I would like to set custom routes in the INVO app https://docs.phalcon.io/en/latest/reference/tutorial-invo.html , but I am not sure how to do that

I would like to be able to hit the controller ContactController and method indexAction by typing https://localhost/contact-us instead of https://localhost/contact

So, I think I have to create routes.php file in the config folder and somehow load the routes in the index.php bootstrap file in my public folder.

But I have no idea how it should look like.

My worry is that I would like to use both contact and contact-us variants to be working and hitting ContactController. Will the security plugin in INVO handle this thing properly or it is not possible and I can use only one of them?



37.0k

Any idea?



3.4k

routes config

$router->add('/contact-us', array(
    'controller' => "contact",
    'action' => "index"
))->setName('contact');

security config

//Private area resources
$privateResources = array(
    'contact' => array('index'),
);


37.0k

Thanks, but if I have this in my config/routes.php

<?php

$router->add('/contact-us', array(
    'controller' => "contact",
    'action' => "index"
))->setName('contact');

The INVO app output a flash message saying: You don't have access to this module

However, I want contact and contact-us be accessible to everybody.

Btw. why you set contact to private resources and not public resources? In INVO app from the github, it's in public resources. Any reason for that?

Should I laod the routes in my bootstrap index.php file or is it done automatically?

Hi Flanex. I'm having the same problem. How did you solve it? Did you solve it? Thanks!

i hope someone solve it

edited Aug '16

I add new function into /App/Services.php it work for me.

<?php
    protected function initRouter(){
        $router = new Router();
        $router->add("/:controller/:action", array(
        'controller' => 1,
        'action' => 2)); 
        $router->add("/tao", array(
        "controller" => "images",
        "action"     => "custom_route"
         ));
         return $router;
}