Yii,更改homeUrl [英] Yii, change homeUrl
问题描述
我有一个多语言网站.我已经设置了 .htaccess 和 urlmanager 规则,它们可以正常工作.剩下最后一件事
i've a multilanguage site. I've set up the .htaccess and urlmanager rules, and they correctly works. One last thing remain
我希望以这种方式直接访问 www.mysite.com 自动附加语言:
I want that direct visit to www.mysite.com auto append the language in this way:
www.mysite.com -> www.mysite.com/en/ or obviously to www.mysite.com/fr/ etc etc
现在按照我的规则,在第一次访问主页后,由于 ovverriden createUrl 的所有链接都正确地变成了 www.mysite.com/en/但如果用户直接在浏览器中写入,则不是第一次访问www.mysite.com
Now with my rules, after the first access to the home, all the links to the home thanks to ovverriden createUrl correctly became www.mysite.com/en/ but not the first access in case a user directly wrote in the browser www.mysite.com
如何使第一个访问网址也成为 www.mysite.com/en/?
How can make also the first access url to became www.mysite.com/en/?
如果不是没有 cookie 或没有会话或没有 GET 或 POST 参数,我可以指定默认语言.
I can assign a default language in case the aren't no cookie or no session or no GET or POST params.
帮帮我!!
推荐答案
如果你的默认控制器是站点/索引,那么你可以这样做.
If your default Controller is site/index, then you can do like this.
public function actionIndex() {
if(!isset($_GET['lang'])){
$this->redirect(array('site/index','lang'=>'de')+$_GET); // 'de' is considered as default language
}
---
}
这篇关于Yii,更改homeUrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!