Custom Filters in Zend Framework

Although there might be tons of articles about this theme I’m going to describe it in breve. What I was supposed to do is to filter a string, which is supposed to be a date, but if only the year or year/month pair were present I should filter them correctly.

So the first thing I tried to achieve is to write a custom Zend Filter. It seem to me a simple task and it is.

The only thing you should do is to define a class in Zend/Filter/ folder with the name of the filter of course. In my case this was Zend_Filter_Mydate, which really sounds very strange, but you can name it after whatever you want.

The only thing you need in that class is a public function filter by giving it one parameter, in most cases, and returning the filtered value.

Here’s a snippet:

<?php
 
require_once 'Zend_Filter_Interface.php'
 
class Zend_Filter_Mydate extends Zend_Filter_Interface
{
 
    public function filter($value)
    {
        // do something with the source and return the filtered value
    }
 
}

Leave a Reply

Your email address will not be published. Required fields are marked *