Zend: Enable autocompletion for your view helpers in your IDE

When working with the Zend framework you might wonder why the view helpers are not getting autocompleted when hitting the ctrl and space keys in your favourite IDE.

The problem

Let’s assume that we want to edit the view template <project-root>/module/Application/view/application/index/index.phtml.

You’ll start with $this and now your code workflow is disturbed because you need to remember what helper functions are available.

    Some content of this view

For the HeadScript helper this means you need to know these functions:

  • appendFile($src, $type = ‘text/javascript’, $attrs = array())
  • offsetSetFile($index, $src, $type = ‘text/javascript’, $attrs = array())
  • prependFile($src, $type = ‘text/javascript’, $attrs = array())
  • setFile($src, $type = ‘text/javascript’, $attrs = array())
  • appendScript($script, $type = ‘text/javascript’, $attrs = array())
  • offsetSetScript($index, $script, $type = ‘text/javascript’, $attrs = array())
  • prependScript($script, $type = ‘text/javascript’, $attrs = array())
  • setScript($script, $type = ‘text/javascript’, $attrs = array())

For every other helper you want to use you need to know their functions as well.

The reason why they are not autocompleted is that they’re dynamicly created through the magic __call method.

The solution

Your problem is quickly solved by introducing the typehint

/* @var $this \Zend\View\Renderer\PhpRenderer */

so that your IDE knows how to autocomplete on the $this keyword.



  1. Torsten

    Useful, thanks for sharing!

  2. Thanks, very useful.

  3. Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>