Answer the question
In order to leave comments, you need to log in
How can I override CUrlManager rules in a Yii module?
such a problem, inherited from CUrlManager:
class UrlManager extends CUrlManager
{
public function createUrl($route,$params=array(),$ampersand='&')
{
if (!isset($params['language'])) {
if (Yii::app()->user->hasState('language'))
Yii::app()->language = Yii::app()->user->getState('language');
else if(isset(Yii::app()->request->cookies['language']))
Yii::app()->language = Yii::app()->request->cookies['language']->value;
$params['language']=Yii::app()->language;
}
return parent::createUrl($route, $params, $ampersand);
}
}
'urlManager'=>array(
'class'=>'application.components.UrlManager',
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<language:(ru|en|kz|de|ch|tu|ar)>/' => 'site/index',
'<language:(ru|en|kz|de|ch|tu|ar)>/<action:(contact|login|logout)>/*' => 'site/<action>',
'<language:(ru|en|kz|de|ch|tu|ar)>/<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<language:(ru|en|kz|de|ch|tu|ar)>/<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<language:(ru|en|kz|de|ch|tu|ar)>/<controller:\w+>/<action:\w+>/*'=>'<controller>/<action>',
'<language:(ru|en|kz|de|ch|tu|ar)>/<module:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>' => '<module>/<controller>/<action>/<id>',
'<language:(ru|en|kz|de|ch|tu|ar)>/<module:\w+>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>',
),
),
Answer the question
In order to leave comments, you need to log in
Look at the implementation https://github.com/mishamx/yii-multilanguage although not everything is perfect there either, short addresses cannot be used in modules without a module name
no one bothers to create a separate config and entry point for the admin panel or separate it at the application level.
Both configs must be inherited from the base one. It is clear that it is somehow strange to interfere with everything in a heap.
The rules are compared from top to bottom and the first match is taken.
For example, if the request /ru/edit-post/12 should send us to the admin module along the path admin-module/post/edit and pass the post id 12. Then the rules look something like this:
'rules'=>array(
'<language:(ru|en|kz|de|ch|tu|ar)>/' => 'site/index',
'<language:(ru|en|kz|de|ch|tu|ar)>/<action:edit-post>/<id:\d+>' => 'admin-module/post/<action>',
...
),
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question