Welcome Guest, Not a member yet? Register   Sign In
CI4 filter before RequestInterface
#1

Hi,

I'm new in CodeIgniter 4. Is it possible to SANITIZE all request variables before using it in controller? 

number_only = '123abc456';
Code:
<?php namespace App\Filters;

use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Filters\FilterInterface;

class SanitizeFields implements FilterInterface
{

    protected $session;

    public function before(RequestInterface $request, $arguments = null)
    {
         $request->getVar('number_only', FILTER_SANITIZE_NUMBER_INT);
    }

    public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
    {
        // Do something here
    }
}
Code:
<?php
//controller
public function getData()
{
    echo $this->request->getVar('number_only');
}


I don't know if it is possible to output the data in controller with the sanitize number_only variable.
Output: 123456

Thanks!
Reply


Messages In This Thread
CI4 filter before RequestInterface - by what2see - 08-26-2020, 09:01 PM



Theme © iAndrew 2016 - Forum software by © MyBB