我是ZF2的新手。我对 url('route-name', $urlParams, $urlOptions); 有疑问 ?>
当模块中有多个控制器时,我应该如何构造 $urlParams 和 $urlOptions?
我将 Album 模块重命名为 Shop,它有两个控制器:indexController 和 VendorController。在视图>商店>供应商>index.phtml,我添加:
<p><a href="<?php echo $this->url('shop', array('action'=>'add')); ?>">
Add new vendor</a></p>
瞄准此链接将链接到 localhost/shop/vendor/add。但页面显示链接是: http ://host.com/shop 而我想要的是 http://host.com/shop/vendor/add
我的理解是我应该设置 $urlOPtions 字段,有人可以举个例子吗?谢谢大家下面是module.config.php:
'router' => array(
'routes' => array(
'shop' => array(
'type' => 'Literal',
'options' => array(
'route' => '/shop',
'defaults' => array(
'__NAMESPACE__' => 'Shop\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(
),
),
),
),
),
),
),
'controllers' => array(
'invokables' => array(
'Shop\Controller\Index' => 'Shop\Controller\IndexController',
'Shop\Controller\Vendor'=> 'Shop\Controller\VendorController'
),
),