Hi all,
I’m creating my first Yii application. I have another problem in my hands. I have a developed the site to have back end and a front end. backed (CMS) is inside the protected/modules/CMS folder. All are working fine and the only problem I’m having is the login and the log out.
-
I have used the Gii to generate my scrips and then customized it.
-
I have a separate “Adminusers” database table and I’m logging in my users according to that (this is working fine)
-
The only problem is I was looking to separate the “login” of the CMS from the front end site but it is still takings the front end’s “siteController” login and log out functions.
-
I also successfully created a separate "LoginController" for the backed and even though it works after login it redirects to the front end.
below is the code of that "LoginController"
class LoginController extends Controller
{
public function actionIndex()
{
$model=new LoginForm;
// if it is ajax validation request
if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
// collect user input data
if(isset($_POST['LoginForm']))
{
$model->attributes=$_POST['LoginForm'];
// validate user input and redirect to the previous page if valid
if($model->validate() && $model->login())
$this->redirect(Yii::app()->homeUrl);
}
// display the login form
$this->render('index',array('model'=>$model));
}
public function actionLogout()
{
Yii::app()->user->logout();
$this->redirect('admincms/login/index');
}
}
I understand the redirection is done by
$this->redirect(Yii::app()->homeUrl)
$this->redirect('admincms/login/index')
but when I use
$this->redirect('admincms/pages/index') it goes to domain/admincms/admincms/pages/index (double admin CMS is not a mistake)
when I use
$this->redirect('pages/index') it goes to domain/pages/index (which is the front end)
I want it to be redirected to domain/admincms/pages/index after login.
And also appreciate if you could direct me to a proper documentation about "redirection"
Please let me know if there is any other better way to separate the backed (CMS) login from the front end completely.
Thank you in advance