Question

am trying to remove the index action from url. just started ZF2 with auth module. my module.config.php looks like as follows.

Using the below code am able to see the login screen, can login and logout but when it comes to Register and Password reset option the url routing is domain/auth/index/registration instead of domain/auth/registration.

Any help is highly appreciated. Thanks in advance.

return array(

'controllers' => array(
    'invokables' => array(
        'Auth\Controller\Index' => 'Auth\Controller\IndexController',
        'Auth\Controller\Registration' => 'Auth\Controller\RegistrationController',
        'Auth\Controller\Admin' => 'Auth\Controller\AdminController',
    ) ,
) ,
'router' => array(
    'routes' => array(
        'auth' => array(
            'type' => 'Segment',
            'options' => array(
                'route' => '/auth[/:action]',
                'defaults' => array(
                    '__NAMESPACE__' => 'Auth\Controller',
                    'controller' => 'Index',
                    'action' => 'index',
                ) ,
            ) ,
            'may_terminate' => true,
            'child_routes' => array(
                'default' => array(
                    'type' => 'Segment',
                    'options' => array(
                        'route' => '/[:controller[/:action[/:id]]]',
                        'constraints' => array(
                            'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'id' => '[a-zA-Z0-9_-]*',
                        ) ,
                        'defaults' => array() ,
                    ) ,
                ) ,
            ) ,
        ) ,
    ) ,
) ,
'view_manager' => array(

    //        'template_map' => array(
    //            'layout/Auth'           => __DIR__ . '/../view/layout/Auth.phtml',
    //        ),

    'template_path_stack' => array(
        'auth' => __DIR__ . '/../view'
    ) ,
    'display_exceptions' => true,
) ,
'service_manager' => array(

    // added for Authentication and Authorization. Without this each time we have to create a new instance.
    // This code should be moved to a module to allow Doctrine to overwrite it

    'aliases' => array( // !!! aliases not alias
        'Zend\Authentication\AuthenticationService' => 'my_auth_service',
    ) ,
    'invokables' => array(
        'my_auth_service' => 'Zend\Authentication\AuthenticationService',
    ) ,
) ,

);

Was it helpful?

Solution

You could try using a "literal" instead of a "segment" type for this route to remove the index from the url:

'auth' => array(
    'type' => 'Zend\Mvc\Router\Http\Literal',
    'options' => array(
        'route'    => '/auth/registration[:/]',
         'defaults' => array(
             '__NAMESPACE__' => 'Auth\Controller',
             'controller'    => 'Index',
             'action'        => 'index',
         ),
     ),
),

From the zf2 docs :"The Literal route is for doing exact matching of the URI path. Configuration therefore is solely the path you want to match, and the “defaults”, or parameters you want returned on a match." http://framework.zend.com/manual/2.0/en/modules/zend.mvc.routing.html#zend-mvc-router-http-literal

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top