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 get uri parameter from index controller [SOLVED]

Hello, I have a group class which is receiving a parameter in the uri but I don't know how to get to it.

This is my url:


edited Oct '14

The default behavior for routing in Phalcon is: /{controller}/{action}/{parameters} For the example you want, you should have a GroupControll.php with an indexAction that receives the "6" as the action parameter. To do this, without having to set the request as "/group/index/6" to respect the default route, you have to create a new route so that you can keep the uri the way you want.

You can create a new route like this:


    //Set routes
    $di->set('router', function(){
        $router = new \Phalcon\Mvc\Router();
                "action"         => "index",

        return $router;

and in you GroupController.php:

class GroupController extends \Phalcon\Mvc\Controller

    public function indexAction($id=null){
       echo "Group Controller; IndexAction; ID $id";


Thanks Vasco, it worked perfectly :D


One more related question please... I'm trying to make it accept numbers and text but I get errors for everything I tried. This is the code:

                "action" => "index",

How should it be? Thanks.

You can improve the regular expression to allow letters and numbers like this: ```php //Define a route $router->add( '/{controller}/{id:[a-zA-Z0-9]+}', array( "action" => "index", ) ); ```

or if you want to allow everything as the parameter, you also can simple do this: ```php //Define a route $router->add( '/{controller}/{id}', array( "action" => "index", ) ); ```


Vasco, thanks again! :D