method routing in zf2

I'm learning method routing in zf2. I make this type of routing, but don't know how to use this in front? It gives me error like, in route array 'type' is not specified.

 'home' => array(
            'type' => 'Zend\Mvc\Router\Http\Literal',
            'options' => array(
                'route'    => '/',
                'defaults' => array(
                    'controller' => 'Application\Controller\Index',
                    'action'     => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'lgn' => array(
                    'type' => 'Zend\Mvc\Router\Http\Method',
                    'options' => array(
                        'verb' => 'post',
                    )
                ),
                'child_routes' => array(
                    'form' => array(
                        'may_terminate' => true,
                        'type' => 'Zend\Mvc\Router\Http\Literal',
                        'options' => array(
                            'route' => '/another',
                            'defaults' => array(
                                'controller' => 'Application\Controller\Index',
                                'action'     => 'another',
                            )
                        )
                    )
                )
            ),
        ),

Answers


It's look like you don't have controller for lng http://framework.zend.com/manual/2.0/en/modules/zend.mvc.routing.html#zend-mvc-router-http-method

 'home' => array(
            'type' => 'Zend\Mvc\Router\Http\Literal',
            'options' => array(
                'route'    => '/',
                'defaults' => array(
                    'controller' => 'Application\Controller\Index',
                    'action'     => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'lgn' => array(
                    'type' => 'Zend\Mvc\Router\Http\Method',
                    'options' => array(
                        'verb' => 'post',
                        'route' => '/post-route',
                        'defaults' => array(
                            'controller' => 'YourController',
                            'action' => 'youtAction',
                        ),
                    ),
                ),
                'child_routes' => array(
                    'form' => array(
                        'may_terminate' => true,
                        'type' => 'Zend\Mvc\Router\Http\Literal',
                        'options' => array(
                            'route' => '/another',
                            'defaults' => array(
                                'controller' => 'Application\Controller\Index',
                                'action'     => 'another',
                            )
                        )
                    )
                )
            ),
        ),

according to documentation it's should look like this


Great answer from Notuser :)

I complete it with my own code, the difference is you can keep the same url but a different route if it's post or get.

In my example for the url: "/user-rest", if it's a get method, zf2 go to indexAction, if it's a post method, zf2 go to createAction

'routes' => array(
    'user-rest' => array(
            'type' => 'Literal',
            'options' => array(
                'route' => '/user-rest',
            ),
            'child_routes' => array(
                'get' => array(
                    'type' => 'method',
                    'options' => array(
                        'verb' => 'get',
                        'defaults' => array(
                            'controller' => 'RestCtrl',
                            'action' => 'index',
                        ),
                    ),
                ),
                'post' => array(
                    'type' => 'method',
                    'options' => array(
                        'verb' => 'post',
                        'defaults' => array(
                            'controller' => 'RestCtrl',
                            'action' => 'create',
                        ),
                    ),
                ),
            ),
        ),

Need Your Help

Why doesn't Node.js have a native DOM?

javascript node.js dom v8 headless-browser

When I discovered that Node.js was built using the V8 JavaScript engine, I thought:

Grails g:render a template (or render a div) onClick event

html list templates grails render

I am creating a hierarchical list with expandable/ collapsible list items. When a user clicks on a list item to expand it a table pops up with some info. Right now, grails is rendering all of the t...