dourangdz750379 2014-11-16 20:54
浏览 26
已采纳

过滤器未被执行

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条回答 默认 最新

  • dtsps00544 2014-11-17 10:28
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算