A view is defined by a view script, an
HTML file that can contain PHP directives. The view
script can use view helpers, which are classes that produce markup.
View helpers are useful when the required markup is complex or used repeatedly in different
locations. Place view helpers in the views/helpers
folder under your
module's folder.
Here is the skeleton of a view helper bar for the
Foo
module:
<?php /** * View helper description * * @copyright copyright info * @license license info * @version version info */ class Foo_View_Helper_Bar extends Zend_View_Helper_Abstract { /** * Bar description * * @param boolean $capitalize Whether the output should be in caps. * @return string the generated markup. */ public function bar($capitalize = false) { return $capitalize ? 'BAR' : 'bar'; } }
To use this view helper in your view script:
The following line outputs bar: <?= $this->bar(); ?> The following line outputs BAR: <?= $this->bar(true); ?>
For more details, see Section 14.4.1, “View Scripts” and the Zend Framework documentation.