Zend 路由翻译网址



1) 我有一个控制器"日历",并有操作"showDate",它通过 url 获取日期。所以,url 类似于"日历/显示日期/日期/2012-07-22"

2)我有一个链接来显示所有条目,"日历/"

所以,我想创建路线,使我的链接看起来像"kalendar/2012-07-22"和"kalendar/"。

谁能帮我?

根据这篇文章:http://www.z-f.fr/forum/viewtopic.php?id=5138

解决方案是在参数中添加"@locale"=> $lang。

$this->url(array('lang'=>'it','@locale'=>'it'))

它对我来说效果很好。

我一直

在研究用Zend_Translate翻译 URL,我遇到了这个网站的插件,它试图自动翻译 URL 段(模块/控制器/操作)。

http://blog.helmich.cz/305-howto-simple-multilingual-routes-in-zend-framework/

好消息是它是一个修改后的自定义路由器类,其功能类似于Zend_Router因此相对熟悉。

$pages = new MyApp_Controller_Router_Route(
    ':locale/:@controller/:@action/*',
    array(
        'controller' =>; 'index',
                'action'     => 'index',
                'locale'     => 'cs'
            )
);
$router->addRoute('pages',$pages);

您需要在URL中包含一个语言ID(在上面的示例中称为:locale),以便您的Zend_Translate可以设置正确的语言。

www.example.com/en/calendar/2012-06-22/
www.example.com/fr/calendrier/2012-06-22/
www.example.com/de/kalender/2012-06-22/
www.example.com/it/calendario/2012-06-22/

我只是稍微玩过这个概念,但我记得它有希望。 您必须更加熟悉Zend_Translate:http://framework.zend.com/manual/en/zend.translate.html

我希望这有所帮助!

干杯!

您可以将日历的所有调用重新路由到 kalendar。有两种可能性,要么使用 Zend(最好)执行此操作,要么更改 Web 服务器配置以使用 HTTP 302 重写对日历的调用(丑陋)。

但是,您应该查阅官方的Zend文档,这非常好。

您必须设置自定义路由,这是我的方式:

在文件夹应用程序/配置/创建名为"routes.ini"的文件

将您的路线归档:

;index-homepage, parameter date isn't required
;"index" is key of your route
routes.index.route = "kalendar/:date" 
routes.index.defaults.controller = calendar
routes.index.defaults.action = show
routes.index.defaults.date =

因此,在您的引导程序中.php定义该配置文件:

protected function _initRoute() {
    $router = Zend_Controller_Front::getInstance()->getRouter();
    $router->addDefaultRoutes();
    $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routes.ini');
    $router->addConfig($config, 'routes');
}

就是这样,您可以调用网址

www.website.com/kalendar

www.website.com/kalendar/2012-1-1

有关详细信息,请参阅此问题的答案:Zend 框架中的简单重写

最新更新