[英]zf2 routing is not working
My root url is http://restaurent.local i want to route like this http://restaurent.local/menuedit/test/1 . 我的根网址是http://restaurent.local,我想像这样http://restaurent.local/menuedit/test/1进行路由。 But this not working This is my code
但这不起作用这是我的代码
'menuedit' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/menuedit[/:action][/:id]',
'defaults' => array(
'controller' => 'Menu\Controller\Menu',
'action' => 'menuedit',
),
),
),
if any one know about this please help me. 如果有人知道这一点,请帮助我。
You're attempting to use a Literal
route type. 您正在尝试使用
Literal
路由类型。 You need a Segment
route type if you want to match your route parameters ... 如果要匹配您的路线参数,则需要
Segment
路线类型...
'menuedit' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/menuedit[/:action][/:id]',
'defaults' => array(
'controller' => 'Menu\Controller\Menu',
'action' => 'menuedit',
),
),
),
Please consider reading the manual to understand the differences and how they're meant to be used -> http://framework.zend.com/manual/2.3/en/modules/zend.mvc.routing.html#http-route-types 请考虑阅读手册,以了解不同之处以及如何使用它们-> http://framework.zend.com/manual/2.3/en/modules/zend.mvc.routing.html#http-route-类型
You might also want to set your constraints for the route parameters. 您可能还需要设置路径参数的约束。 I'd also make the trailing backslash optional with
[/]
otherwise it won't match /route/to/
it would only match /route/to
我还将使反斜杠与
[/]
成为可选,否则它将与/route/to/
不匹配,而只会与/route/to
匹配
'menuedit' => array(
'type' => 'segment',
'options' => array(
'route' => '/menuedit[/][:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => [0-9]*'
),
'defaults' => array(
'controller' => 'Menu\Controller\Menu',
'action' => 'menuedit',
),
),
),
I Literal route can't handle params. 我的文字路线无法处理参数。
'type' => 'Zend\Mvc\Router\Http\Literal',
You want to edit a specific menu, with specific id, this is a param. 您要编辑具有特定ID的特定菜单,这是一个参数。
For handle param you have to use Segment type. 对于句柄参数,您必须使用细分类型。
Don't forget to add constraints option for your action AND your id. 不要忘记为操作和ID添加约束选项。 More secure.
更安全。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.