I have following routes in my module.config.php
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => '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' => array(
'type' => 'Literal',
'options' => array(
'route' => '/application',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
),
and I have following URLs in my Layout.phtml file.
<li class="active"><a href="<?php echo $this->url('home') ?>"><?php echo $this->translate('Home') ?></a></li>
<li class="active"><a href="<?php echo $this->url('application',array('controller'=> 'mycontrollername', 'action'=>'index')) ?>"><?php echo $this->translate('My URL') ?></a></li>
Home link is working fine, for second dynamic one, It should look like this. <a href="/application/mycontrollername/index">My URL</a>
But instead it is generating this
<a href="/application">My URL</a>
Any Idea?
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.
http://framework.zend.com/manual/2.0/en/modules/zend.mvc.plugins.html#the-url-plugin
ZF2: Get module name (or route) in the application layout for menu highlight
http://framework.zend.com/manual/2.0/en/modules/zend.view.helpers.html#url-helper