2

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 Answer 1

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,

Sign up to request clarification or add additional context in comments.

1 Comment

It helped, thank you. It's too bad the ZF patch for the traverseArray decorator never made it in. framework.zend.com/issues/browse/ZF-4354

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.