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.

Have PhalconPHP accepts params as $_GET key/value pairs


I would like Phalcon to pass parameters in the URL as GET values, e.g:


would trigger the indexAction funciton in the TestsController.php, and pass: name => dew id => 29

as get values. Is this possible?

I am migrating to Phalcon from Yii, where this was standard, which is why I need it. I tried figuring it out with the Routers documentation, but could'nt figure it out.

Thanks for your help! Alex

edited Sep '14

Hi Alex,

You can access those values in the controller in two ways:

Using the default way: http://localhost/www/phalconproject/tests/index/dew/28

public function indexAction($name, $id)
    echo $name;
    echo $id;


Using the request parameter : http://localhost/www/phalconproject/tests/?name=dew&id=29

public function indexAction()
    //Make sure to apply filters accordingly
    $name = $this->request->getQuery("name");
    $id = $this->request->getQuery("id");

More info here:

edited Sep '14

Thanks Dan!

That would indeed work, but the problem with solution 1 is, that you have to pass the params in the precise order. The clients that consume the API, do not neccesarily put these in the same orders.

Solution 2 would tackle that, but then all those clients consuming the API would need to be rewritten, they would have to use instead of:



...which is why I am looking for a way to have Phalcon deal with not have to force all those client changes. I appreciate your help though, hope that there is an easy 'hack' / workaround to accomplish this.

edited Sep '14

Wait, I found the solution, thanks to the link Dan provided:

public function showAction()
        $year = $this->dispatcher->getParam('year');
        $postTitle = $this->dispatcher->getParam('postTitle');

So using the dispatcher allows you to capture the values. I am marking his answer as the accepted one, as he pointed me to the solution.


Actually I cheered too early.

It looks like one needs to hack into the Phalcon\Mvc\Dispatcher exactly how it is described here:

As I am a total newbie, where does this code go? In my custom BaseController that extends Phalcon\Mvc\Controller?

Thanks for anyone's help. Alex