Setting Page Title - headTitle() - Zend Framework 2 ZF2

Jucks picture Jucks · Apr 5, 2013 · Viewed 8.3k times · Source

I am currently in the process of building an application with ZF2, everything is going well so far, but I am just having trouble with the page titles (as in the <title> tag in the <head>).

In my layout.phtml I have it statically set a string using $this->headTitle().

I want it to basically include the name of the module, controller and action by default, just like the doc page suggests:
http://framework.zend.com/manual/2.1/en/modules/zend.view.helpers.head-title.html

However when I try and implement the example code, I get an Exception. Frankly the documentation should at least show you the best place to put this code.

I am looking for an example that a ZF2 noob can follow. I basically want to place some code somewhere (presumably Application\Module.php) so that I can set the default title as "Module - Controller - Action", then I need an example of how to override it easily from each controller or view (whichever is preferred)... please help! :)

Answer

Jucks picture Jucks · Apr 5, 2013

As per Sams comment... Readthedocs has the working example: http://zf2.readthedocs.org/en/latest/modules/zend.view.helpers.html#headtitle-helper

Thanks for your help Sam!