1

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?

4

1 に答える 1

2

InputFilterフィルタリングされたデータを取得するには、データを取得する必要があります。

だからあなたのリスナーの中で:

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

$data代わりにその配列を引き続き使用します。

$datacreate メソッドのパラメーターは、未加工/フィルター処理されていないPOSTデータです。$dataクライアントから送信されたものはすべてそこにあるため、それをメソッドのソースとして使用する場合は注意が必要です。

これは、Apigility のドキュメントではあまり明確に説明されていないと思います。多くのユーザーがこの間違いを犯していると思います。これについては GitHub の問題に書きました。

于 2014-11-17T10:28:41.210 に答える