The below code is the behaviors of siteController.php. When I used to logged in it shows “The page isn’t redirecting properly”.
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['login','error','index', 'logout','addhotels'],
'rules' => [
[
'allow' => true,
'actions' => ['index', 'logout','addhotels'],
'roles' => ['@'],
],
[
'allow' => true,
'actions' => ['login','error'],
'roles' => ['?'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
SiteController.php
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new AdminLoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->redirect(array('index'));
} else {
$this->layout = '//loginLayout';
return $this->render('login', [
'model' => $model,
]);
}
}
AdminLoginForm.php
public function login()
{
if ($this->validate()) {
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
} else {
return false;
}
}
public function getUser()
{
if ($this->_user === false) {
$this->_user = Admin::findByUsername($this->username);
}
return $this->_user;
}
Here I post the SiteController.php and AdminLoginForm.php code. Its working in localhost but not in live site. May RBAC will help me in anyway? I updated my beta yii2.0. Is there anything to do with AccessRoles?