首页 > 代码库 > YII实战笔记-后台登录注册
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 }
YII实战笔记-后台登录注册
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。