Soroush Rabiei
Soroush Rabiei

Reputation: 10868

ZF2 routing not works properly

I have a ZF2 project based on the provided skeleton. I've made some controllers and actions using ZFTool. The problem is that router does not accepts URLs. It says: The requested URL could not be matched by routing

Notes:

  1. The project is on an Apache Virtual Host

  2. Controllers are created:

    $ 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. And router have been configured like this:

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

Upvotes: 0

Views: 591

Answers (1)

Bram Gerritsen
Bram Gerritsen

Reputation: 7238

The segemented controller/action route is registered as a child route under application, this means you must type application in front: www.mysite.local.com/application/user/register. If you don't want this you have to change your route definitions.

Upvotes: 2

Related Questions