How to define route in phalcon

987 views Asked by At

I have controller named GlossaryController with 2 actions indexAction and anotherAction in view i have a directory glossary and index.volt file

i want to define a route with parameters for example http://localhost/project/glossary/another/params it should redirect me to indexAction with parameters

1

There are 1 answers

0
ermacmkx On BEST ANSWER

In your routes.php file in app/config folder add this line:

$router->add("/glossary/another/{param1}/?{param2}", array(
    "controller" => "Glossary",
    "action"     => "another",
));

And your anotherAction method will be like:

public function anotherAction($param1, $param2 = 0) {
//some code
}

This way first param must be sent, second one is optional, you can add this way as much params as you like.

See official docs for various ways of routing: https://olddocs.phalconphp.com/en/3.0.3/reference/routing.html