0

How to allow all sub actions inside that controller with one router rule? For example this follow:

visit: site/login                - works only
       site/login/forgetpassword - does not work
       site/login/remmeberme     - does not work

Example:

$router = $e->getApplication()->getServiceManager()->get('router');
$route = Http\Literal::factory(array(
  'route' => '/login',
  'defaults' => array(
    'controller' => 'Application\Controller\Login',
    'action' => 'index'
  ),
));
$router->addRoute('login', $route, null);

Follow up:

How can i make it so that /login and /login/anything works?

$route = Http\Segment::factory(array(
  'route' => '/login[/:action]',
  'defaults' => array(
    'controller' => 'Application\Controller\Login',
    'action' => 'index'
  ),
));
$router->addRoute('login', $route, null);

1 Answers1

1

There is an excellent QuickStart Tutorial available within the official Documentation. Set up your route like the following to be allowed multiple actions and an ID Parameter. Fur further information please take a look at the documentation.

You may also be interested in DASPRiDs presentation from ZendCon2012

 'router' => array(
    'routes' => array(
        'album' => array(
            'type'    => 'segment',
            'options' => array(
                'route'    => '/album[/:action][/:id]',
                'constraints' => array(
                    'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id'     => '[0-9]+',
                ),
                'defaults' => array(
                    'controller' => 'Album\Controller\Album',
                    'action'     => 'index',
                ),
            ),
        ),
    ),
),
Sam
  • 16,435
  • 6
  • 55
  • 89
  • module.config.php: you are using this right? I am not looking for that, i am using in Module.php bootstrap. –  Oct 30 '12 at 12:48
  • module.config.php: routing concept is time consuming, because the largest array it become. it kills more time to debug, but the Module.php is debug friendly method. Therefore, i have selected the option doing manual routing from Bootstrap but ignoring routing from module.config.php. –  Oct 30 '12 at 12:54
  • 1
    Totally up to you, but it doesn't really change anything :) The array-options are those you have to use for your manual call, too. Instead of using a `Http\Literal` simply use `Http\Segment`. Personally i'm using Literal routes only from module.config.php and the speed disadvantage is within very little ms scope so i don't really bother at all ;) – Sam Oct 30 '12 at 13:18