0

如何使用一个路由器规则允许该控制器内的所有子操作?例如以下:

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

例子:

$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);

跟进:

我怎样才能让它 /login 和 /login/anything 工作?

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

1 回答 1

1

官方文档中有一个出色的快速入门教程。如下设置您的路线以允许多个操作和一个 ID 参数。更多信息请查看文档。

您可能还对来自 ZendCon2012的DASPRiDs 演示感兴趣

 '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',
                ),
            ),
        ),
    ),
),
于 2012-10-30T12:20:43.633 回答