Dear Friend
I want to share my experience after simulating your scenario in my localhost.
I am not able to address whole issue.just later part of it.
1.After modifying the .htaccess file as mentioned in this post, I am getting the same error you got it.
2.Once I change the urlFormat from ‘path’ to ‘get’, There are no more errors. But all the url rules declared in urlManager are neglected.
3.Obviously I have to change the "showScriptName" to true in order to make path format working.
4.If you want just to add "en" before the controllerId in url, without analyzing user request and without directing to different language domains, the following modification simply works.
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>true,
'rules'=>array(
'en/'.'<controller:\w+>s'=>'<controller>/index',
'en/'.'<controller:\w+>/<id:\d+>/*'=>'<controller>/view',
'en/'.'<controller:\w+>/<action:\w+>/<id:\d+>/*'=>'<controller>/<action>',
'en/'.'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'en/'.'<controller:\w+>/<action:\w+>/<id:\d+>/*'=>'<controller>/<action>',
),
),
These are the things I am getting in navigation bar.
http://localhost/blog/index.php/en/posts
http://localhost/blog/index.php/en/post/7
http://localhost/blog/index.php/en/post/create
http://localhost/blog/index.php/en/post/update/10
http://localhost/blog/index.php/en/post/admin
I do not know these are the things you expected or I am doing just stupid things.
The situation becomes bit complicated once we want to change the language part of url based on the user request.
For example, in home page we are having many links displaying different languages. When user clicks it, he is
directed towards the pages related to the particular language. After clicking the particular language every url
following that should contain the particular language in it.
Suppose I have the following links in my home page.
<a href="http://localhost/blog/index.php?r=site/index&lang=en_us">English</a>
<a href="http://localhost/blog/index.php?r=site/index&lang=fr_fr">French</a>
In the above example, we are going to get the language by GET parameter. You can also choose the language by
POST method by displaying a drop down list.
The language we get can be made stateful by the following way.
if($this->request->getParam('lang')!==null)
{
$this->user->setState('language',$this->request->getParam('lang'));
$this->language=$this->user->getState('language');
}
Now we can get the language at any place by calling Yii::app()->language.
But we can not make the following to work.
Yii::app()->language."/".'<controller:\w+>/<action:\w+>'=>'<controller>/<action>'
In typical Yii application, the url rules in main configuration file are set even before the user request is analysed. Any url rules declared in main config file with runtime variables attached to urls will throw
errors.We have to make the rules at the time when user request is analysed.
This can be done by attaching a behavior to main web application and rising an event at appropriate time.
I am creating applicationBehavior.php file at components folder.
<?php
class applicationBehavior extends CBehavior
{ private $_owner;
public function events()
{
return array(
'onBeginRequest'=>'rewriteUrl',
);
}
public function rewriteUrl()
{
$this->_owner=$this->getOwner();
$this->_owner->getRequest();
if($this->_owner->request->getParam('lang')!==null)
//getParam can get both GET and POST parameters.
{
$this->_owner->user->setState('language',$this->_owner->request->getParam('lang'));
$this->_owner->language=$this->_owner->user->getState('language');
}
if($this->_owner->user->hasState('language'))
$this->_owner->language=$this->_owner->user->getState('language');
$this->_owner->urlManager->urlFormat="path";
//Here you can add as many as url rules. For simplicity I added one.
$this->_owner->urlManager->addRules(array(
$this->_owner->language.'/'.'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
));
}
}
?>
The following should be attached to main configuration file as a property.
'behaviors'=>array(
'class'=>'application.components.applicationBehavior',
),
Do not declare the url rules at main config file. Make it void.
'urlManager'=>array(
'showScriptName'=>true,
'rules'=>array(
),
Now whenever user clicks particular language link, all the urls following that will bear the language.
For example, if user clicks "french", following will follow.
http://localhost/blog/index.php/fr_fr/site/index
http://localhost/blog/index.php/fr_fr/site/contact
http://localhost/blog/index.php/fr_fr/post/index
http://localhost/blog/index.php/fr_fr/post/view?id=7
If user clicks "english", urls will have en_us attached.
http://localhost/blog/index.php/en_us/site/index
http://localhost/blog/index.php/en_us/post/classify
http://localhost/blog/index.php/en_us/comment/approval
Expecting some inputs…
Regards.