Php 从URL-Zend Framework 1.12和路由中删除控制器索引

Php 从URL-Zend Framework 1.12和路由中删除控制器索引,php,zend-framework,routing,zend-framework-mvc,Php,Zend Framework,Routing,Zend Framework Mvc,在我的项目中,我在我的索引控制器中定义了一些页面,比如ie的“关于我们”页面。为了使我不必键入domain.com/index/about而是domain.com/about,我有以下方法: $route = new Zend_Controller_Router_Route_Static ( 'about', array ( 'controller' => 'Index', 'action' => 'about' ) ); $router->a

在我的项目中,我在我的索引控制器中定义了一些页面,比如ie的“关于我们”页面。为了使我不必键入
domain.com/index/about
而是
domain.com/about
,我有以下方法:

$route = new Zend_Controller_Router_Route_Static ( 'about', array (
        'controller' => 'Index',
        'action' => 'about'
) );

$router->addRoute ( 'about', $route );

它起作用了。问题是,有时我有6或7页,我必须重复这条路线6或7次。有没有一种方法可以让我执行一个总是从url中删除“
index
”的路由?我永远不需要一个包含
索引的url。谢谢

您可以通过避免静态路由类型来编写动态路由:

    $route = new Zend_Controller_Router_Route(
        '/:action', 
        array (
            'controller' => 'index',
            'action' => 'index',
        )
    );
    $router->addRoute('pages', $route);
这将添加一个名为“页面”的路由,该路由将匹配索引控制器中的任何单个操作。此路由中定义的操作和控制器只是默认值,由于您没有将控制器作为变量传递,因此它将始终路由到IndexController。该操作将默认为indexAction,但可被路由覆盖,即:

/about -> IndexController / aboutAction
/contact -> IndexController / contactAction
etc ...
请记住,这将覆盖任何其他路由,因此您需要正确地构建路由继承机制。稍后在流程中定义的管线将覆盖已定义的管线

有关更多信息,请查看文档: