The Helpers, Zend_View_Helper

Wednesday, May 5, 2010 | 0 comments
zendframework zend_view

These helpers are a useful tool in ZendFramework, most often used to save code or perform tasks that otherwise would be very difficult or expensive.

The simplest way to use a "Helper" is in a View:

 <base href="<?php echo $this->baseUrl(); ?>" />

but we can also use them within a controller, or where we have access to the current view

 <?php
 $this->_helper->getHelper('thehelper');

Most Class Helpers Zend_View_Helper_Abstract descederan for extra functionality already implemented so as access to system objects, but also can make simple assistants without additional overhead, see a helper that shows the date,

 <?php
 /**
  * Localized Date
  */
 class News_View_Helper_Pintafecha
 {
     /**
      * Actualo Date
      *
      * @return string
      */
     public function pintafechas()
     {
      $date = new Zend_Date();
      return $date->get(Zend_Date::DATE_FULL); 
     }
 }



Thus we can save young aides to code and give consistency to the programs.
Remember that the helper's must be located within our directory tree at:

          ../application/views/helpers
          ../application/modules/<module>/views/helpers 

taking the latter limited visibility to your module, if desired helpers have wide application located in our library, maintaining "good practices", in:

..library/My/View/Helper

and report their existence to the system of codes:

 <?php
 
 $view->setHelperPath('/path/to/more/helpers', 'My_View_Helper');

or in the configuration file:

....
resources.view.helperPath.My_View_Helper="My/View/Helper"

If you need more power, we will inherit from another class Zend_View_Helper_Abstract or descent, more specialized.

Bookmark this article at these sites

Comments on this article

No comments for this article.

Leave us a comment

Feel free to write whatever you want that is related to the article.

Just to show avatar from gravatar.com

Copyright (c) 2012 Valclip Version 1.0.23dev


valclip   +34 677 62.74.00