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

 1 <?php
 2 
 3 namespace app\modules\controllers;
 4 
 5 use yii\web\Controller;
 6 use app\models\Admin;
 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值