We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon\Mvc\Url::get() append query params examples

Anybody know how to use the newly merged Phalcon\Mvc\Url::get() to append query params (https://github.com/phalcon/cphalcon/pull/877)? Usage example pls?



98.9k
$url = new Phalcon\Mvc\Url();
echo $url->get('/show/products', array('id' => 1, 'name' => 'Carrots')), "\n"; // /show/products?id=1&name=Carrots


51.3k

@Phalcon - since your example does not require any non-default routes to exist, I assumed that going to

https://..../show/products?id=1&name=Carrots

would make values of "id" and "name" available in Router or Dispatcher.

Unfortunately, that did not happen. What should I do to get those values, apart from fetching them from $_GET?

Thanks, Temuri



309

Since you have these in the Query string, you should use the $this->request object:

$this->request->getQuery('id', 'int');
$this->request->getQuery('name', 'string');