Zend framework2 Zend Framework 2路由操作
我在运行“localhost/products/edit”时收到一个错误 我做错了什么?当然,我有编辑功能 视图中的Product controller classand edit.htmlZend framework2 Zend Framework 2路由操作,zend-framework2,Zend Framework2,我在运行“localhost/products/edit”时收到一个错误 我做错了什么?当然,我有编辑功能 视图中的Product controller classand edit.html 'products' => array( 'type' => 'Literal', 'options' => array( 'route' => '/products',
'products' => array(
'type' => 'Literal',
'options' => array(
'route' => '/products',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Products',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/products[/:action]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
),
'controllers' => array(
'invokables' => array(
'Application\Controller\Index' => 'Application\Controller\IndexController',
'Application\Controller\Products' => 'Application\Controller\ProductsController'
)
),
)) 尝试将其作为子根数组:
'child_routes' => array(
'view' => array(
'type' => 'segment',
'options' => array(
'route' => '/:id',
'constraints' => array(
'id' => '[0-9]+',
),
'defaults' => array(
'action' => 'view',
),
),
'may_terminate' => true,
'child_routes' => array(
'actions' => array(
'type' => 'segment',
'options' => array(
'route' => '/:action',
'constraints' => array(
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Application\Controller\ProductsController,
'action' => 'view', ),
),
),
),
),
),
此外,它还需要是localhost/products/[:id]/edit,就像localhost/products/1/edit一样,而不是localhost/products/edit,我可以想象,但我不知道你做了什么才能公平。只需删除id参数和约束,它就可以工作了
请注意,子根操作不会重复路由,因为它是继承的。。。您的路线将创建类似/products/products/edit的内容错误消息是什么?如果可以的话,可能值得发布一个分条控制器。”未找到404错误页面。请求的URL无法通过路由匹配。没有异常可用“现在我在子路由中有了ok=>/:action,工作正常:)bu使用echo$this->URL('products',array('action'=>'edit')查看文件;仅返回/products/:($this->url('products/actions',array('action'=>'edit'));但您需要像我的示例中那样将默认值更新为actions,否则它将是$this->url('products/default',array('action'=>'edit'));可能比较您的代码和我的示例代码中child_routes下的行,您应该明白我的意思。不幸的是,我遇到了一个错误:找不到名为“actions”的路由