PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Adding Filter Class Namespaces

By default, when you declare a filter or validator as a string, Zend_Filter_Input searches for the corresponding classes under the Zend_Filter or Zend_Validate namespaces. For example, a filter named by the string 'digits' is found in the class Zend_Filter_Digits.

If you write your own filter or validator classes, or use filters or validators provided by a third-party, the classes may exist in different namespaces than Zend_Filter or Zend_Validate. You can tell Zend_Filter_Input to search more namespaces. You can specify namespaces in the constructor options:

<?php
$options 
= array('filterNamespace' => 'My_Namespace_Filter',
                 
'validatorNamespace' => 'My_Namespace_Validate');
$input = new Zend_Filter_Input($filters$validators$data$options);

Alternatively, you can use the addValidatorPrefixPath($prefix, $path) or addFilterPrefixPath($prefix, $path) methods, which directly proxy to the plugin loader that is used by Zend_Filter_Input:

<?php
$input
->addValidatorPrefixPath('Other_Namespace''Other/Namespace');
$input->addFilterPrefixPath('Foo_Namespace''Foo/Namespace');

// Now the search order for validators is:
// 1. My_Namespace_Validate
// 2. Other_Namespace
// 3. Zend_Validate

// The search order for filters is:
// 1. My_Namespace_Filter
// 2. Foo_Namespace
// 3. Zend_Filter

You cannot remove Zend_Filter and Zend_Validate as namespaces, you only can add namespaces. User-defined namespaces are searched first, Zend namespaces are searched last.

Note

As of version 1.5 the function addNamespace($namespace) was deprecated and exchanged with the plugin loader and the addFilterPrefixPath() and addValidatorPrefixPath() were added. Also the constant Zend_Filter_Input::INPUT_NAMESPACE is now deprecated. The constants Zend_Filter_Input::VALIDATOR_NAMESPACE and Zend_Filter_Input::FILTER_NAMESPACE are available in releases after 1.7.0.

Note

As of version 1.0.4, Zend_Filter_Input::NAMESPACE, having value namespace, was changed to Zend_Filter_Input::INPUT_NAMESPACE, having value inputNamespace, in order to comply with the PHP 5.3 reservation of the keyword namespace.

Zend Framework