Filter Component

Sanitizing Action Parameters

If you have used the Phalcon\Di\FactoryDefault as your DI container, the Phalcon\Filter\FilterLocator is already registered for you with the default sanitizers. To access it we can use the name filter. If you do not use the Phalcon\Di\FactoryDefault container, you will need to set the service up in it, so that it can be accessible in your controllers.

We can sanitize values passed into controller actions as follows:


use Phalcon\Filter\FilterLocator;
use Phalcon\Mvc\Controller;

 * Class ProductsController
 * @property FilterLocator $filter
class ProductsController extends Controller
    public function showAction($productId)
        $productId = $this->filter->sanitize($productId, 'absint');