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

Custom routes not working

Hello,

i have tried to create a simple custom route, but it is not working. I want to override /about into /ueber-uns. Phalcon version 3.0 and PHP 7.0.8

Controller: About Action: index

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

 $router->add('/ueber-uns', [
    'controller' => 'about_control',
    'action' => 'index'
 ]);

 return $router;

Rgds Stefan

I might be missing something in your query but this is what you have.

Controller : About

in your route you call controller "aboutControl"



59.9k

Hello Jed,

thank you for your reply, but nothing works right now. This is a simple link <a href="/about"> and i want to change the /about into /ueber-uns.

Do you have another idea?

Rgds Stefan

edited Jun '18

Can you change the code to the following and test

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

$router->add('/ueber-uns', [ 'controller' => 'about', 'action' => 'index' ]);

return $router;



59.9k

Hello Jed,

thx again, but it changes also nothing. I am using Vokuro, maybe it helps.

Rgds Stefan

Hello Unfortunately unless you can send me a link to your github repo or send me some kind of error I cant help you further.

edited Jun '18

So when a user visits /about, do you want to redirect them to /ueber-uns, or just have them see the output from ueberUnsController::index() with the url unchanged?



59.9k
edited Jun '18

Hello Dylan,

i have the AboutController::index() and i want to override the url from /about to /ueber-uns or to /blabla whatever i want. Because i want to implement mult-language in next steps EN, GER, FR ....

Is this possible?

Rgds Stefan

If you want to change the url, then you want a redirect, not a route: https://docs.phalcon.io/en/3.3/response#redirections

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live