码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-06-01 00:30:14      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:post   str   blog   ace   渲染   span   log   goback   xtend   

 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 }

 

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

标签:post   str   blog   ace   渲染   span   log   goback   xtend   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!