How To Access View Object From View Helper

From your view helepr you might want to access

  • view object properties
  • the view object
  • another view helper

You will be able to do all of the above if the view object is available in your view helper. To make sure view object is available to your helper do any of the following

  • Easiest method: Extend Zend_View_Helper_Abstract
    Example:
    <?php
    class My_View_Helper extends Zend_View_Helper_Abstract{}
    ?>
  • Implement the Zend_View_Helper_Interface
  • Define the setView() method in your helper
    <?php
    public $view;

        function 
    setView(Zend_View_Interface $view) {
            
    $this->view $view;
        }

    ?>

Once the view object is accessible in your view helper, you can call another view helper. For example,

<?php
$this
->view->OtherHelper();
?>

About the author

Sudheer is an entrepreneur and software developer. Get more from Sudheer on Twitter.


Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>. The supported tag styles are: <foo>, [foo].

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.