Hi,
I have the following pieces of code:
- in the main config:
'urlManager'=>array(
'class'=>'application.components.MyUrlMan',
'urlFormat'=>'path',
'showScriptName'=>false,
'urlSuffix'=>'.php',
'rules'=>array(
'<lang:[a-z]{2}>/' => 'site/index',
'<lang:[a-z]{2}>/<view:about>'=>'site/page',
'<lang:[a-z]{2}>/<_a:(contact|login|logout|home)>' => 'site/<_a>',
'<lang:[a-z]{2}>/<_c:\w+>s' => '<_c>/index',
'<lang:[a-z]{2}>/<_c:\w+>/<id:\d+>'=>'<_c>/view',
'<lang:[a-z]{2}>/<_c:\w+>/<_a:\w+>/<id:\d+>'=>'<_c>/<_a>',
'<lang:[a-z]{2}>/<_c:\w+>/<_a:\w+>'=>'<_c>/<_a>',
),
- and I created a controller with a class to overwrite the CUrlManager (simplified; Yii::app()->language is set somewhere else):
class MyUrlMan extends CUrlManager
{
public function createUrl($route,$params=array(),$ampersand='&')
{
if (!isset($params['lang'])) {
$params['lang']=Yii::app()->language;
}
return parent::createUrl($route, $params, $ampersand);
}
}
The links are (almost) correctly generated. So for language "en": /en/about.php, /en/login.php, etc. But I have two issues:
[list=1][]with the rule ‘<lang:[a-z]{2}>/’ => ‘site/index’, I’d expect to have a link “/en/”, but I get “/en.php” instead.[] when displaying for example /en/login.php, $_GET[“lang”] is empty as if there is no parameter “lang=en”. If I don’t use ‘urlFormat’=>‘path’, I get links like “?r=site/login&lang=en” after which $_GET[“lang”] has “en” as expected.[/list]
Anyone knows, why I can’t get what I expect?
Thanks,
Rabb