wardog
(Icristianrc)
May 7, 2015, 3:11am
1
Hello,
try to set a subdomain for a controller/action.
My controller is shaped account/user
where url is: mydomain.local/account/user/id/669
and I desire to be of the form:
username.mydomain.local
I have tried using the extension: yii-behavior-sluggable
and added a field "slug" in table user
and the model add:
behaviors public function () {
return array (
'Sluggable' => array (
'class' => 'ext.SluggableBehavior.SluggableBehavior'
'columns' => array ('username'),
'unique' => true,
'update' => true,
)
);
}
and add in config.php (urlManager):
'<slug: \ w +>. mydomain.local /' => 'account / profile'
but it does not work on localhost, there’s something I’m forgetting?
regards
muet84
(Jawwad Software)
May 7, 2015, 1:53pm
2
I m not sure that following will address your problem but you may do the same in the controller.php by checking the url and either redirect or load the required controller/action
May this help
$baseurl = Yii::app()->getBaseUrl(true);
if(substr($baseurl,0, 4) == "http") $baseurl = substr($baseurl, 7, strlen($baseurl));
$baseurl = explode( '.', $baseurl);
// print_r($baseurl);
// print ">>".$baseurl[0]; die;
if(Yii::app()->user->isAdmin() and ($baseurl[0]=='uatadmin' or $baseurl[1]=='uatadmin')){
$this->layout = 'admin';
}else if($baseurl[0]=='uatadmin' || $baseurl[1]=='uatadmin'){
$this->redirect('/user/auth');
}else if($baseurl[1]!='uatadmin' and Yii::app()->user->isAdmin()){
$this->redirect('/user/auth/logout');
}
}
and I just check he did using the Site router will another way to accomplish.
http://www.yiiframework.com/forum/index.php?/topic/4645-dynamic-default-controller/
What exactly is not working? Can you generate the desired URL, or if it is not working when you visit username.mydomain.local? Did you set username.mydomain.local as pointing to 127.0.0.1?