ZF2路由无法正常工作

时间:2013-12-06 19:14:19

标签: php zend-framework2

我有一个基于提供的骨架的ZF2项目。我使用ZFTool制作了一些控制器和动作。问题是路由器不接受URL。它说:The requested URL could not be matched by routing

备注:

  1. 该项目位于Apache虚拟主机上

  2. 创建控制器:

    $ 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.
    
  3. 路由器配置如下:

    // ...
    '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(
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),  
    

1 个答案:

答案 0 :(得分:2)

分段controller/action路由在application下注册为子路由,这意味着您必须在前面键入应用程序:www.mysite.local.com/application/user/register。 如果您不想这样,则必须更改路线定义。