【问题标题】:Remove Index from indexController in zend framework application从 zend 框架应用程序中的 indexController 中删除索引
【发布时间】:2014-01-17 05:10:11
【问题描述】:

我想从索引控制器生成的每个操作中从 url 中删除索引词。

domain.com/index/user/id/1
它应该是 domain.com/user/id/1
和
domain.com/index/home
应该是 domain.com/home

我该怎么做?如果您有解决方案,请告诉我。
我正在使用 zf1.12

【问题讨论】:

    标签: php mysql .htaccess zend-framework


    【解决方案1】:

    您可以在您的 Bootstrap.php 中执行此操作(尽管在 application.ini 中)。将此添加到 Bootstrap:

    Bootstrap.php(未经测试)

    /**
     * Setup Routig. 
     * Now all calls are send to indexController like
     * URL/ACTION-1
     * URL/ACTION-2
     *
     * @return void
     **/
    protected function _initRouters()
    {
        $router = Zend_Controller_Front::getInstance()->getRouter();
    
        $route = new Zend_Controller_Router_Route(
            ':action/*',
            array(
                'controller' => 'index',
                'action' => 'index'
            )
        );        
    
        $router->addRoute('default', $route);
    }
    

    Application.ini(未经测试)

    routes.index.type = "Zend_Controller_Router_Route"
    routes.index.route = "/"
    routes.index.defaults.module = "default"
    routes.index.defaults.controller = "index"
    routes.index.defaults.action = "index"
    

    【讨论】:

    • 它对我来说工作正常,但为什么这行 Zend_Controller_Front::getInstance().我们可以在不创建实例的情况下做到这一点吗?
    • 哼不知道,没试过。只需使用 applications.ini ;)
    • 这个 $router->addRoute( 如何在 zend 框架中工作?
    • 查看文档或这个不错的教程:blog.jebrini.net/post/1431025228/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-30
    • 1970-01-01
    • 2014-10-10
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多