问题描述
如何使路由自动适用于ZF1结构中的所有内容?
How can I make the routing automatically work for everything in the ZF1 structure?
module / controller / action / par1Name / par1Val / par2Name / par2Val /
module/controller/action/par1Name/par1Val/par2Name/par2Val/
我阅读了有关路由的信息,但是从我的角度来看,我必须手动添加所有操作,并且看到可选参数存在问题...
I read the information about routing, but the way I see it, I'd have to add all actions manually, and I see a problem with optional params...
推荐答案
您可以至少在每个控制器的基础上设置通配符child_route以获得类似于zf1的路由:
You can set up a wildcard child_route, at least on a per-controller basis, to get zf1-like routes:
'products' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/products[/:action]',
'defaults' => array(
'controller' => 'Application\Controller\Products',
'action' => 'index'
)
),
'may_terminate' => true,
'child_routes' => array(
'wildcard' => array(
'type' => 'Wildcard'
)
)
)
然后您可以使用url()视图助手:
Then you can use, for instance, the url() view helper:
$this->url('products/wildcard',array('action'=>'edit','id'=>5,'foo'=>'bar');
会生成类似/ products / edit / id / 5 / foo / bar的网址
which will produce a url like /products/edit/id/5/foo/bar
这篇关于ZF1中的ZF2路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!