![](/img/trans.png)
[英]Getting 404 (Page Not Found) error while calling Controller Action from Jquery in Zend Framework
[英]Zend Framework 2 (ZF2) 404 Page not found error when calling action
我从ZF2 Skeleton Application开始 。 我有一个名为Application
的模块。 在该模块内,我添加了自己的ShopController
。 它注册在看起来像这样的module.config.php
中。
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
),
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/application',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
'shop' => array(
'type' => 'segment',
'options' => array(
'route' => '/shop[/][:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Shop',
'action' => 'index',
),
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/: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\Shop' => 'Application\Controller\ShopController',
),
),
[... service_manager,translator,view_manager as in skeleton app ...]
);
我可以通过浏览到my.example.com/shop/来达到商店负责人的索引操作,但是当我尝试进行其他操作(例如my.example.com/shop/add)时,它就无法工作。 我得到404。
我想念什么?
我尝试添加may_terminate = true,它正在工作,也删除了child_routes可以工作。
'shop' => array(
'type' => 'segment',
'options' => array(
'route' => '/shop[/][:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Shop',
'action' => 'index',
),
),
'may_terminate' => true, // I added this
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.