我在zf2中学习方法路由。我做了这种类型的路由,但不知道如何在前面使用它?它给出了错误,例如路径数组' type'未指定。
'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',
)
)
)
)
),
),
答案 0 :(得分:0)
看起来你没有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',
)
)
)
)
),
),
根据文档,它应该看起来像这样
答案 1 :(得分:0)
Notuser的好回答:)
我用我自己的代码完成它,区别在于你可以保持相同的网址,但如果它发布或获得的话,可以采用不同的路线。
在我的url示例中:&#34; / user-rest&#34;如果是get方法,zf2转到indexAction,如果是post方法,zf2转到createAction < / p>
'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',
),
),
),
),
),