Home>Article>PHP Framework> How to implement backend login interface in thinkphp5

How to implement backend login interface in thinkphp5

尚
forward
2020-05-15 09:15:49 8494browse

How to implement backend login interface in thinkphp5

1. Unzip the "tp5" compressed package to "thinkphp_5.0.24_with_extend\"(E);

2. Put the unzipped "tp5 folder"— >Rename "demo (you can give other names)"->Copy the demo folder to the WWW directory;

3. Enter "http://127.0.0.1/demo/public" in the browser "—> Check whether tp5 can be used;

4. Create or import a database (I imported it);

5. In the application folder—> Create the admin folder —>In the admin folder—>Create controller,

model, and view folders respectively—>In the controller folder—>Create Login.php;

D: \phpStudy\WWW\demo\application\admin\controller\Login.php

Content

paginate(3); // $this->assign('linkres',$linkres); if(request()->isPost()){ $login=new Log; $status=$login->login(input('username'),input('password')); if($status==1){ return $this->success('登录成功,正在跳转!','Index/index'); }elseif($status==2){ return $this->error('账号或者密码错误!'); }else{ return $this->error('用户不存在!'); } } return $this->fetch('login'); } public function logout(){ session(null); return $this->success('退出成功!',url('index')); } }

6. In the model folder—>Create the Login.php file

D:\phpStudy\WWW\demo\application\admin\model\Login.php

Content:

where('username','=',$username)->find(); if($admin){ if($admin['password']==md5($password)){ \think\Session::set('id',$admin['id']); \think\Session::set('username',$admin['username']); return 1; }else{ return 2; } }else{ return 3; } } }

7. In the view folder—>Create the Login folder—> ;In the Login folder—>Create the login.html file

D:\phpStudy\WWW\demo\application\admin\view\Login\login.html

Content:

    后台登录  

8.D:\phpStudy\WWW\demo\application\config.php

// 应用调试模式 'app_debug' => false,

Modify it to:

'app_debug' => true,

and you will see the bug!

The template file does not exist: D:\phpStudy\WWW\demo\public/../application/admin\view\login\login.html

The login file name under view is wrong! ! ! *Use uppercase Login in Login.php under controller and model, and lowercase Login in login.html under view!

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) The bug appears because there is no connection to the database

D:\phpStudy\WWW\ demo\application\database.php

Fill in the content

return [ // 数据库类型 'type' => 'mysql', // 服务器地址 'hostname' => '127.0.0.1', // 数据库名 'database' => 'youme', //你创建或导入的数据库名 // 用户名 'username' => 'root', // 密码 'password' => '****', // 端口 'hostport' => '', // 连接dsn 'dsn' => '', // 数据库连接参数 'params' => [], // 数据库编码默认采用utf8 'charset' => 'utf8', // 数据库表前缀 'prefix' => 'ym_', // 你创建或导入数据库表名的前缀 ***************************************************************************************** SQLSTATE[42S02]: Base table or view not found: 1146 Table 'youhe.admin' doesn't exist(Bug)

D:\phpStudy\WWW\demo\application\admin\model\Login.php

where('username','=',$username)->find(); $user= \think\Db::name('user')->where('username','=',$username)->find(); // if($admin){ if($user){ // if($admin['password']==md5($password)){ if($user['password']==$password){ // \think\Session::set('id',$admin['id']); \think\Session::set('id',$user['id']); // \think\Session::set('username',$admin['username']); \think\Session::set('username',$user['username']); return 1; }else{ return 2; } }else{ return 3; } } }

Recommended tutorial: 《

TP5

The above is the detailed content of How to implement backend login interface in thinkphp5. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete