Passing an array as a value to Zend_Filter

て烟熏妆下的殇ゞ 提交于 2019-12-07 23:44:53

问题


I'm trying to implode an array by using the Zend_Filter_Interface.

Here's my simplified test case.

class My_Filter_Implode implements Zend_Filter_Interface
{
    public function filter($value)
    {
        return implode(',', $value);
    }
}

The input will be an array.

$rawInput = array('items' => array('a', 'b', 'c'));

$validators = array(
    'items' => array()
)

$filters = array(
    'items' => 'Implode'
);

$filterInput = new Zend_Filter_Input($filters, $validators, $rawInput, $options);

I would like the filter to transform array('a', 'b', 'c') to a string 'a,b,c'. It is instead applying the filter to each item in the array. How can the value passed to filter() be passed as an array?


回答1:


Your filter seems to be OK. The problem is in Zend_Filter_Input, which passes individually the values in the array to the filters and validators.

There is a discussion thread about this problem, along with some possible workarounds here: http://zend-framework-community.634137.n4.nabble.com/Zend-Filter-Input-and-Arrays-td653511.html

Hope that helps,



来源:https://stackoverflow.com/questions/8252293/passing-an-array-as-a-value-to-zend-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!