class MyFilter implements Zend_Filter_Interface
{
public function filter($value)
{
// perform some transformation upon $value to arrive on $valueFiltered
return $valueFiltered;
}
}
添加上述过滤器的实例到过滤器链中:
$filterChain = new Zend_Filter();
$filterChain->addFilter(new MyFilter());
/**
* EmailMaskFilter
* A simple custom filter that will hide a part of the email
* letting user to see only the first letter and the domain
* the rest part uf the email is filled with wildcards
* ex: t***@gmail.com
*/
class EmailMaskFilter implements Zend_Filter_Interface
{
public function filter($value)
{
$mask = str_pad('', strpos($value, '@') - 1, '*');
$valueFiltered = substr_replace($value, $mask, 1, strlen($mask));
return $valueFiltered;
}
}
then you can call the filter something like
$usernameElement= new Zend_Form_Element_Text('username');
$usernameElement->addFilter(new CustomLibrary_Filter_MyFilter)
Comments
* EmailMaskFilter
* A simple custom filter that will hide a part of the email
* letting user to see only the first letter and the domain
* the rest part uf the email is filled with wildcards
* ex: t***@gmail.com
*/
class EmailMaskFilter implements Zend_Filter_Interface
{
public function filter($value)
{
$mask = str_pad('', strpos($value, '@') - 1, '*');
$valueFiltered = substr_replace($value, $mask, 1, strlen($mask));
return $valueFiltered;
}
}
The question of DoubleG is totally appropriate! How can you think to illustate how to write a custom filter without even tell WHERE to put it???
This is simple crazy.
then you can call the filter something like
$usernameElement= new Zend_Form_Element_Text('username');
$usernameElement->addFilter(new CustomLibrary_Filter_MyFilter)