1

我正在尝试将操作映射到基本 URL 和默认控制器。

发誓这应该是直截了当的,甚至是“开箱即用”的功能,但是如何使用 Zend 框架将默认控制器中的操作映射到基本 url?我对框架相当陌生,所以我希望我只是错过了一些明显的东西。

尝试映射:

domain.com/index/my-page 到 domain.com/my-page

默认情况下不会破坏任何其他路由设置。

我可以使用 Zend_Router 破解它,但它违反了其他规则,例如 /:controller/:action /:module/:controller/:action

注意:/index/my-page 是一个示例 url - 我需要它动态地为所有 indexController 操作工作。

'tharkun' indexController 请求的 URL 映射示例具有方法 indexAction 和 contactAction 需要 url

/index
/index/contact
/
/contact

第二个控制器 testController 有方法 indexAction 和 monkeyAction 需要 url

/test
/test/index
/test/monkey

基本上 - 如果系统找不到 VAR 的控制器,那么它会在默认控制器中查找 VAR 的操作

4

1 回答 1

2

The default controller is IndexController.

The (default) mapping works like this:

/ => IndexController::indexAction
/index => IndexController::indexAction
/index/foo => indexController::fooAction
/foo => FooController::indexAction

So, add a user defined route like this (will have lower priority than the default)

$frontController = Zend_Controller_Front::getInstance();
$router = $frontController->getRouter();
$route = new Zend_Controller_Router_Route(
    '/:action',
    array(
        'controller' => 'index'
    )
);
$router->addRoute('user', $route);

This did not break my use of the default routes.

Edit: As coffeerings said in the comment, this will break the indexAction of non-default controllers.

于 2009-01-05T14:59:34.807 回答