filters are not being executed

117 views Asked by At

I'm writing a PHP 5.6 application using apigility 1.0.4 and zend framework 2.3.3

with apigility I created a new reset service called drink and created a filed called "drink_flavor".

I used the following filters:

Zend\Filter\StringToLower
Zend\Filter\StringTrim

now I use postman to test it.

so i configured the url to http://url/drink I'm sending post data with raw json with the following text:

{"drink_flavor" : " AAA"}

as you can see i have a space at the beginning and the letters are capital.

now if my controller code i have the following:

public function create($data)
{
    die(var_export($data,1));
}

so i'm just printing the data.

if I understood everything correctly instead of getting ' AAA' i should have gotten 'aaa' because of my filters but I still got the unmodified data which is " AAA".

any ideas what's missing?

1

There are 1 answers

0
Wilt On BEST ANSWER

You have to pull the data from you InputFilter to get the filtered data.

So inside your listener:

// Get filtered data
$inputFilter = $this->getInputFilter();
$data = $inputFilter->getValues(); 

And continue to use that $data array instead.

The $data param in your create method is the raw/unfiltered POST data. You should be careful using that $data as a source for your methods since anything sent by the client will be in there.

I think this is not so clearly explained in the Apigility documentation and I think that a lot of users make this mistake. I wrote about this in an issue on GitHub.