First, let’s update our layout to link to the blog module, so that when we visit the homepage we don’t have to type in the URL to go the blog.
/module/Application/view/layout/layout.phtml and find the string
echo $this->url(‘home’) contained in an HTML
<li></li> element. As we can see just above it, the Zend Framework logo also points to this location (home), making the actual navigation element superfluous. So, let’s replace it with a link to the blog.
Replace the entire
<li> with the code below:
1 2 3 4 5 <li> <a href="<?= $this->url('blog') ?>"> <?= $this->translate('Blog') ?> </a> </li>
Navigate to the home. Notice that now instead of ‘Home’ it says ‘Blog’ next to the ZF2 logo, and it actually works. 😉
$this-url($route) is a ViewHelper already present in Zend Framework. It searches for a route with the same name and translates it to a URI to print. This comes back to one of the reasons why we print the full route names in comment code in our module
routes.config.php files. It makes them easy to look up and figure out the full route name.