We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Route based on query string


I would like to make a route for https://mysite.com/?s=cap&searchfor=pages to another controller than index. I've tried this, but is not working

        'controller'    => 'page',
        'action'        => 'search'

edited Sep '17

Afaik routes only operate on the path component of the URI

You can handle it with dispatching:

class IndexController extends \Phalcon\Mvc\Controller {
    public function indexAction()
        if($this->request->hasQuery('s') && $this->request->hasQuery('searchfor')) {
              'controller' => 'page',
              'action' => 'search'
edited Sep '17

Query parameters are part of $_GET in php. Use request->hasQuery

Thanks Lajos. Worth to remember your solution. I've made a 301 redirect from htaccess in the end, because my main concern was the old searches indexed in google.