You haven't understood the ZF naming conventions correctly.

Since your code is in My/Filter/Slash2Comma.php, the class name should be
My_Filter_Slash2Comma, not Zend_Filter_Slash2Comma.

Also, no reason for you to have an Interface.php in My/Filter/ - this file
already exists in Zend/Filter/Interface.php.  Don't touch this file!

The line
$mysearch->addPrefixPath('My_Filter', 'My/Filter/', 'filter');
tells the form element to look for filters in the My/Filter directory
prefixed My_Filter.  (You would typically want to set this for the whole
form - $this->addPrefixPath() in your example - so you don't have to set it
for each element).


Yours,
Mark





Customize wrote:
> 
> Related to my previous post on slash(/) on query string, I wanted to
> implement my custom filter.
> 
> OK I think understand some concept of custom filter. Now I have custom
> filter implemented but it is not working.
> 
> I have
> /application
>  /library
>    /My
>      /Filter
>         Interface.php
>         Slash2Comma.php
> 
> Basically my idea is to replace the slash(/) with comma (,) and this is
> how it looks like
> 
> Interface.php
> ++++++++++++++
> <?php
> 
> interface Zend_Filter_Interface
> {
>    /**
>     * Returns the result of filtering $value
>     *
>     * @param  mixed $value
>     * @throws Zend_Filter_Exception If filtering $value is impossible
>     * @return mixed
>     */
>    public function filter($value);
> }
> +++++++++++++++
> 
> Slash2Comma.php
> +++++++++++++++++
> <?php
> 
> require_once 'Zend/Filter/Interface.php';
> 
> class Zend_Filter_Slash2Comma implements Zend_Filter_Interface
> {
>    /**
>     * Defined by Zend_Filter_Interface
>     *
>     * Returns the string $value, replacing all forward slashes to comma
>     *
>     * @param  string $value
>     * @return string
>     */
>    public function filter($value)
>    {
>                $temparr = explode("/", $value);
>                $replacedvalue = implode (",", $temparr);
>                return (string) $replacedvalue;
>                //also tried
>                //return str_replace("/",",", (string) $value);
>                //plus this one too
>                //return preg_replace("/\/",",", (string) $value);
>    }
> }
> 
> ++++++++++++++++
> 
> 
> In My Form element, I have added my custom filter
> 
> The code fragment in my form looks like this
> ++++++++++++
> public function init()
> {
>       $mysearch = New Zend_Form_Element_Text('srchstr');
>       $mysearch->setLabel('Search For:');
>       $mysearch->setAttrib('size', '30');
>       $mysearch->addPrefixPath('My_Filter', 'My/Filter/', 'filter');
>       $mysearch->addFilter('Slash2Comma');
>       $mysearch->addFilter('StringTrim');
> ...
> ...
> ...
> }
> 
> +++++++++++++++
> 
> Now when I var_dump my query string, it is still the same. What's
> wrong with my Slash2Comma code? Any suggestion?
> 
> Besides that if i execute query, i am getting SQL error
> 
> Sorry I still don't fully understand how to implement this.
> 
> Some correction is greatly appreciated.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Custom-Filter-Question-tp24076250p24090777.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to