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?
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