Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZF2 Routing as in ZF1

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

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...

like image 916
Kris Avatar asked Dec 11 '22 22:12

Kris


1 Answers

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

like image 144
timdev Avatar answered Dec 21 '22 01:12

timdev