我的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(
),
),
),
),
),
),
),
我的Layout.phtml文件中有以下网址。
<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>
首页链接工作正常,对于第二个动态链接,应该看起来像这样。 <a href="/application/mycontrollername/index">My URL</a>
但它正在产生这个
<a href="/application">My URL</a>
任何想法?
我检查了以下链接,但这些都没有帮我解决这个问题。我更喜欢使用URl Helper而不是硬代码。
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
答案 0 :(得分:4)
<?php echo $this->url ('application/default', array ('controller' => 'xxx', 'action' => 'x')); ?>