【问题标题】:PHP Zend Routing for languages not complying with modules不符合模块的语言的 PHP Zend 路由
【发布时间】:2013-03-13 02:14:49
【问题描述】:

我的引导程序中有以下代码。但是,它运行良好,除了默认的任何模块,它都会重定向到默认模块。我怎样才能让它与默认模块以外的模块一起使用?

protected function _initRoutes()
{
    $this->bootstrap(array('FrontController'));
    $router = $this->getResource('Frontcontroller')->getRouter();
    $router->removeDefaultRoutes();
    $language = new Zend_Controller_Router_Route(
         ':language', array('language' =>'en')
    );
    $module = new Zend_Controller_Router_Route_Module(
      array(
      'module'    => 'default',
      'controller'=> 'index',
              'action'    => 'index'
       ),
       Zend_Controller_Front::getInstance()->getDispatcher(),
       Zend_Controller_Front::getInstance()->getRequest()
    );
    $module->isAbstract(true);
    $default = new Zend_Controller_Router_Route_Chain();
    $default->chain($language);
    $default->chain($module);
    $router->addRoute('default', $default);
}

【问题讨论】:

    标签: php zend-framework zend-locale


    【解决方案1】:

    Here is and example 如何将语言路由与默认路由链接到不同的模块。

    您不应在 $module 路由中将模块指定为“默认”

    $module = new Zend_Controller_Router_Route_Module(
       array(),
       Zend_Controller_Front::getInstance()->getDispatcher(),
       Zend_Controller_Front::getInstance()->getRequest()
    );
    

    【讨论】:

    • 完美运行。我唯一的问题是,如果我们位于基本路径并且 URL 中没有 :language,我想重定向到 url/:language。我该如何做到这一点?
    • 您可以使用视图助手或操作助手 url 并将语言作为参数传递。例如。 <?=$this->url(array("language" => "fr"), null, true)?>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-09
    • 2013-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多