我的 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 文件中有以下 URL。
<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:在应用程序布局中获取模块名称(或路由)以进行菜单突出显示
http://framework.zend.com/manual/2.0/en/modules/zend.view.helpers.html#url-helper