ZF2 Routing as in ZF1

后端 未结 2 1411
别跟我提以往
别跟我提以往 2021-02-03 15:25

How can I make the routing automatically work for everything in the ZF1 structure?

module/controller/action/par1Name/par1Val/par2Name/par2Val/

I read the informa

2条回答
  •  春和景丽
    2021-02-03 16:05

    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'
                        )
                    )
                )
    

    Then you can use, for instance, the url() view helper:

    $this->url('products/wildcard',array('action'=>'edit','id'=>5,'foo'=>'bar');
    

    which will produce a url like /products/edit/id/5/foo/bar

提交回复
热议问题