Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to disable routes cahing in Phalcon during development?

I am unable to do changes in routes, because the changes in the app/config/routes.php didn't reflect what I put there.

E.g. I put there this:

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

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


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

and then I did this (commented the alias):

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

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


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

And now neither contact nor contact-us works. I am redirected to the homepage ;(

How to automatically rebuild Phalcon routes during development?



21.5k
edited Jul '14

Is it because of this? ->setName("contact")

How to "unset" it back? Where is the "set" info stored? in some file or in the RAM?

Could I set rebuilding of routes in Phalcon during development on every page reload like the volt templates can be refreshed via 'compileAlways' => true ?



21.5k
edited Jul '14

Any idea how to reset the stored routes on every page refresh?

Is there any opposite to the setName() function? Or some "unset" or " reset" option?



83.2k

Calling $router->handle(); manually is not required, this method must be invoked by the dispatcher



21.5k
edited Jul '14

OK, thanks for that I wil remove $router->handle();.

What about the not working contact? Only contact-us works now ;(

Before I used the routes, contact worked. Now only contact-us work.

It's strange because if I comment the routes code in the bootstrap index.php file in the public folder:

```/$di->set('router', function() { $router = new \Phalcon\Mvc\Router(); $router->mount(new Routes()); return $router; });/ ```

It still don't get back.

Like if it's stored in some file or cache or something.

how to reset that?



83.2k
Accepted
answer

That's because:

$router = new Phalcon\Mvc\Router(false); // disable default routes

It must be:

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


21.5k
edited Jul '14

Wow, finally! It's working ;D. Thank you.

One subquestion though... How can I turn off specific routes?

E.g.

contact and contact-us I want both to point to ContactController, however, from posts and articles, i want to allow only articles to point to PostsController. But as default route posts will point to PostsController automatically.

How to do that?



83.2k

There's no way to do that since default routes are defined using regular expressions: https://github.com/phalcon/cphalcon/blob/2.0.0/phalcon/mvc/router.zep#L108



21.5k

So, the only way is to turn off all default routes and define my own?



83.2k

yes, that's the only way