Question: What is zend view helper?
View Helpers are common file(s) which is available in every view file.
Most of the time we kept helpers file in views/helpers/
Following the simple following steps to use view helper.
-
Open configs\application.ini, Add Following line
resources.view.helperPath.Application_View_Helper = APPLICATION_PATH "/views/helpers"
- Create General.php file in application\views\helpers (Might be need to create helpers folder)
-
Add Following code in General.php
class Zend_View_Helper_General extends Zend_View_Helper_Abstract { function General(){ return $this; } function twice($a) { return $a * 2; } function thrice($a) { return $a * 3; } }
- Test Following in any view files
echo $this->General()->twice(2);//4 echo $this->General()->thrice(2);//6 echo $this->General()->twice(3);//6 echo $this->General()->thrice(3);//9
- Done
If above is not working in other modules like admin, then copy/paste following function in Bootstrap.php
protected function _initViewHelpers() { $this->bootstrap('layout'); $layout = $this->getResource("layout"); $view = $layout->getView(); $view->addHelperPath(APPLICATION_PATH . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'helpers', "Application_View_Helper"); }