我有一个基于提供的骨架的ZF2项目。我使用ZFTool
制作了一些控制器和动作。问题是路由器不接受URL。它说:The requested URL could not be matched by routing
备注:
该项目位于Apache虚拟主机上
创建控制器:
$ zf.php create controller user Application
The controller user has been created in module Application.
$zf.php create action register user Application
Creating action 'register' in controller 'Application\Controller\user'.
Created view script at ./module/Application/view/application/user/register.phtml
The action register has been created in controller Application\Controller\user.
路由器配置如下:
// ...
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
),
// The following is a route to simplify getting started creating
// new controllers and actions without needing to create a new
// module. Simply drop new controllers in, and you can access them
// using the path /application/:controller/:action
'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(
),
),
),
),
),
),
),
答案 0 :(得分:2)
分段controller/action
路由在application
下注册为子路由,这意味着您必须在前面键入应用程序:www.mysite.local.com/application/user/register
。
如果您不想这样,则必须更改路线定义。