- 2008-04-24 (Thu) 7:00
- General
intro
This article shows an example of usage of Zend_Filter. It is used for filtering output of variables of view.
1.Create Controller
Create the file
application/controllers/FilterController.php with the following content.
<?php require_once 'Zend/Controller/Action.php'; require_once 'Zend/Filter.php'; require_once 'Zend/Filter/Input.php'; class FilterController extends Zend_Controller_Action { protected function _getOutputFilter($data) { $chain = new Zend_Filter(); $chain->addFilter(new Zend_Filter_StringToLower()); // add other filters $filters = array( '*' => $chain, 'number' => array(array('PregReplace', '/^1$/', 'ONE!')), 'column' => 'Word_UnderScoreToCamelCase' ); $of = new Zend_Filter_Input($filters, null, $data); return $of; } public function indexAction() { $values = array( 'number' => '1', 'column' => 'my_table_column', 'message' => 'THIS IS <b>TAG</b>' ); $this->view->of = $this->_getOutputFilter($values); $this->view->values = $values; } }
2.Create View
Create the file
application/views/script/filter/index.phtml with the following content.
<ul> <?php foreach($this->values as $key => $value) : ?> <li><?= $this->of->$key ?></li> <?php endforeach; ?> </ul>
3.Result of Execution
Below is the output of view.
* ONE!
* MyTableColumn
* this is <b>tag</b>
Comments:0
Trackbacks:0
- Trackback URL for this entry
- http://www.oplabo.com/article/32/trackback
- Listed below are links to weblogs that reference
- Usage of Zend_Filter from Open Programming Laboratory