1

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

ZF2 - Generating Url from route

ZF2 - Get controller name into layout/views

Community
  • 1
  • 1
Developer
  • 25,073
  • 20
  • 81
  • 128

1 Answers1

4
<?php echo $this->url ('application/default', array ('controller' => 'xxx', 'action' => 'x')); ?>
akond
  • 15,865
  • 4
  • 35
  • 55
  • What the hell!? Why putting default in front of the module name make it work? – MurifoX Jun 25 '15 at 20:20
  • Oh, now i get it. This is a named route right? I can have many of that with different names that maps to different stuff? – MurifoX Jun 25 '15 at 20:35