Bla*_*ake 7 php zend-framework2
我的Zend Framework 2应用程序有一个路由定义,试图模仿默认的Zend Framework 1路由.看起来像:
'router' => array(
'routes' => array(
'default' => array(
'type' => 'segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'wildcard' => array(
'type' => 'wildcard',
),
),
),
),
),
Run Code Online (Sandbox Code Playgroud)
它匹配路由就好了,但我无法使用Url视图助手组装具有任意参数的路径.
例如,
$this->url('default', array('controller' => 'test', 'action' => 'test', 'id' => 5));
Run Code Online (Sandbox Code Playgroud)
结果/test/test不是/test/test/id/5.
有谁知道如何组装这样的部分路线?或者有更好的方式获得ZF1风格的路线?
Bla*_*ake 10
事实证明,您需要在Url视图助手中指定整个路径名称(包括子路径).
使用我的问题中定义的路由器,正确的视图助手调用如下所示:
$this->url('default/wildcard', array('controller' => 'test', 'action' => 'test', 'id' => 5));
Run Code Online (Sandbox Code Playgroud)
这将导致一个网址/test/test/id/5.
| 归档时间: |
|
| 查看次数: |
6053 次 |
| 最近记录: |