title: zf2 $this-url with dynamic routes
body: <p>I have following routes in my module.config.php</p>
  
  <pre><code>'router' =&gt; array(
          'routes' =&gt; array(
              'home' =&gt; array(
                  'type' =&gt; 'Zend\Mvc\Router\Http\Literal',
                  'options' =&gt; array(
                      'route'    =&gt; '/',
                      'defaults' =&gt; array(
                          'controller' =&gt; 'Application\Controller\Index',
                          'action'     =&gt; 'index',
                      ),
                  ),
              ),
              // The following is a route to simplify getting started creating
              // new controllers and actions without needing to create a new
              // module. Simply drop new controllers in, and you can access them
              // using the path /application/:controller/:action
              'application' =&gt; array(
                  'type'    =&gt; 'Literal',
                  'options' =&gt; array(
                      'route'    =&gt; '/application',
                      'defaults' =&gt; array(
                          '__NAMESPACE__' =&gt; 'Application\Controller',
                          'controller'    =&gt; 'Index',
                          'action'        =&gt; 'index',
                      ),
                  ),
                  'may_terminate' =&gt; true,
                  'child_routes' =&gt; array(
                      'default' =&gt; array(
                          'type'    =&gt; 'Segment',
                          'options' =&gt; array(
                              'route'    =&gt; '/[:controller[/:action]]',
                              'constraints' =&gt; array(
                                  'controller' =&gt; '[a-zA-Z][a-zA-Z0-9_-]*',
                                  'action'     =&gt; '[a-zA-Z][a-zA-Z0-9_-]*',
                              ),
                              'defaults' =&gt; array(
                              ),
                          ),
                      ),
                  ),
              ),
          ),
      ),
  </code></pre>
  
  <p>and I have following URLs in my Layout.phtml file. </p>
  
  <pre><code>&lt;li class="active"&gt;&lt;a href="&lt;?php echo $this-&gt;url('home') ?&gt;"&gt;&lt;?php echo $this-&gt;translate('Home') ?&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;li class="active"&gt;&lt;a href="&lt;?php echo $this-&gt;url('application',array('controller'=&gt; 'mycontrollername', 'action'=&gt;'index')) ?&gt;"&gt;&lt;?php echo $this-&gt;translate('My URL') ?&gt;&lt;/a&gt;&lt;/li&gt;
  </code></pre>
  
  <p>Home link is working fine, for second dynamic one, It should look like this. <code>&lt;a href="/application/mycontrollername/index"&gt;My URL&lt;/a&gt;</code></p>
  
  <p>But instead it is generating this
  <code>&lt;a href="/application"&gt;My URL&lt;/a&gt;</code></p>
  
  <p>Any Idea?</p>
  
  <p>I have checked following links but none of these helped me to sort this problem. I prefer to use URl Helper rather then hard code it.  </p>
  
  <p><a href="http://framework.zend.com/manual/2.0/en/modules/zend.mvc.plugins.html#the-url-plugin" rel="nofollow noreferrer">http://framework.zend.com/manual/2.0/en/modules/zend.mvc.plugins.html#the-url-plugin</a></p>
  
  <p><a href="https://stackoverflow.com/questions/16077159/zf2-get-module-name-or-route-in-the-application-layout-for-menu-highlight">ZF2: Get module name (or route) in the application layout for menu highlight</a></p>
  
  <p><a href="http://framework.zend.com/manual/2.0/en/modules/zend.view.helpers.html#url-helper" rel="nofollow noreferrer">http://framework.zend.com/manual/2.0/en/modules/zend.view.helpers.html#url-helper</a></p>
  
  <p><a href="https://stackoverflow.com/questions/15766231/zf2-generating-url-from-route">ZF2 - Generating Url from route</a></p>
  
  <p><a href="https://stackoverflow.com/questions/8843092/zf2-get-controller-name-into-layout-views">ZF2 - Get controller name into layout/views</a></p>