YII实战笔记-后台登录注册

 1 <?php
 2 
 3 namespace appmodulescontrollers;
 4 
 5 use yiiwebController;
 6 use appmodelsAdmin;
 7 use yii;
 8 /**
 9  * Default controller for the `admin` module
10  */
11 class LoginController extends Controller
12 {
13     /**
14      * Renders the index view for the module
15      * @return string
16      */
17     public function actionSignin()
18     {
19         $this->layout = false;//去掉头部和尾部
20         $model = new Admin;
21         if ( Yii::$app->request->isPost ) {//如果是post请求
22              $post = Yii::$app->request->post();//接收post请求
23              if ($model->login($post)) {
24                  $this->redirect(['index/index']);//跳转到后台首页
25                  Yii::$app->end();//结束,下面代码不执行
26              }
27          } 
28         return $this->render('signin',["model"=>$model]);//渲染视图 传递数据
29     }
30 
31   //退出方法
32     public function actionLogout()
33     {
34         // //清除session
35         Yii::$app->session->removeAll();
36         if (Yii::$app->session['admin']['isLogin']) {
37             $this->redirect(['login/signin']);
38         }
39 
40         $this->goback();
41     }
42 
43 
44 }

原文地址:https://www.cnblogs.com/zhoupufelix/p/6926286.html