backend\controllers\SiteController::actionLogin PHP Method

actionLogin() public method

public actionLogin ( )
    public function actionLogin()
    {
        if (!\Yii::$app->user->isGuest) {
            return $this->goHome();
        }
        $model = new LoginForm();
        if ($model->load(Yii::$app->request->post()) && $model->loginAdmin()) {
            return $this->goBack();
        } else {
            $data['model'] = $model;
            return $this->render('login', $data);
        }
    }

Usage Example

 /**
  * Deletes an existing Category model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     if (Yii::$app->user->can('admin')) {
         $this->findModel($id)->delete();
         return $this->redirect(['index']);
     } else {
         return parent::actionLogin();
     }
 }