ZendFramework 2 - How to make all the actions available with one router rule? Its only allowing action index

StackOverflow https://stackoverflow.com/questions/13138621

문제

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);
도움이 되었습니까?

해결책

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',
                ),
            ),
        ),
    ),
),
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top