0

I am using INVO example app from here:

https://github.com/phalcon/invo

I have copied all the files and set the db and base url.

It works, I can login etc.

however, I wanted to learn how to use redirects e.g.

I would like to use contact-us instead of contact without changing the name of the controller.

So, I created a file routes.php inside of the app/config folder and put this inside:

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

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

$router->handle();
return $router;

and I have created this in my bootstrap file index.php in the public root directory

$di = new \Phalcon\DI\FactoryDefault();

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

However, it's not working and when I try to access http://localhost/test/contact-us it works, but http://localhost/test/contact-us stopped working and I am redirected to the homepage.

If I (comment the route) do this:

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

$router->handle();
return $router;

Neither http://localhost/test/contact-us nor http://localhost/test/contact-us works ;(.

If I uncomment it back. contact-us works but contact don't.

I guess it's b/c of ->setName('contact') and it's stored in the memory or in some file.

how to get it back to the original state and "unset" that?

user3797244
  • 53
  • 1
  • 5

1 Answers1

0

You can create two routes and each will work:

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

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

Or use groups of routes.

So, if you have ContactController and don't want to access it using /contact url you should add router to the DI container. After that the pages will be available only via router and default /controller/action request format will not work.

Phantom
  • 1,704
  • 4
  • 17
  • 32