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

A dependency injection object is required to access the 'filter' service

If I do as it is written in the documentation — https://docs.phalcon.io/en/latest/api/Phalcon_Http_Request.html

use Phalcon\Mvc\Controller;
use Phalcon\Http\Request;

$request = new Request();
$name = $request->getPost("name", "email");

And I get an error: A dependency injection object is required to access the 'filter' service

But If I do so:

use Phalcon\Mvc\Controller;

$name = $this->request->getPost("name", "string");
$phone = $this->request->getPost("phone", "string");

All OK.



16.0k
Accepted
answer

in the api documentation you get an example of how you can implement the request in bootstrap and then in controller you call it from DI. If you're going to do new Request() in each action, of course you'll get an empty request all the time.