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

Accessing request parameters in controller using request object

Hi guys:

I am a newbie to the beautiful world of Phalcon, and have got stuck for almost a long time. My question is as follows: The following code snippet works like a charm: public function someAction($age) { // Do things with $age } However, I wonder how I can do it without using formal parameters but instead using $this->request->getPost('age') for example. When doing this, I get NULL ($_GET and $_POST are also NULL). Should I define a new Routing/Dispatching scheme for this to happen? Why $_GET (and/or $_POST) array is not populated correctly in this case and only contains:

array(1) { ["_url"]=> string(16) "/person/some/age/2" }

class PersonController extends Phalcon\Mvc\Controller { public function someAction() { // $this->request->getPost('age'), $this->request->getQuery('age'), $_GET, and $_POST are all NULL here } } Access URL I used to test: https://localhost/myapp/person/some/age/40



98.9k

This ?age=2 will populate $_GET, Using method="post" in your form will populate $_POST

You can get the parameters making them work as you want: https://docs.phalcon.io/en/latest/reference/dispatching.html#preparing-parameters

Thanks a lot dude...Keep up the good work! Viva Phalcon and its awesome team!