ThinkPHP5.0框架开发实现简单的页面跳转

一、效果

登录界面

ThinkPHP5.0框架开发实现简单的页面跳转_THinkPHP课程

 

 

登录成功界面

ThinkPHP5.0框架开发实现简单的页面跳转_登录页面_02

 

 

登录失败界面

ThinkPHP5.0框架开发实现简单的页面跳转_php_03

 

二、目录结构

ThinkPHP5.0框架开发实现简单的页面跳转_php_04

 

 

三、代码

控制器中的Login.php



1 <?php 
2 // 声明命名空间
3
4 namespace app\index\controller;
5
6 // 引入系统控制器
7
8 use think\Controller;
9 // 声明控制器
10
11 class Login extends Controller{
12
13 // 登录页面
14
15 public function index(){
16
17 // 加载登录页面
18
19 return view();
20 }
21
22 // 处理登录的提交页面
23
24 public function check(){
25
26 // 接收数据
27
28 $username=$_POST['username'];
29 $password=$_POST['password'];
30
31 // 判断是否登录成功
32
33 if ($username=="admin" && $password=="123") {
34 // 成功之后跳转
35 // $this->success(提示信息,跳转地址,用户自定义数据,跳转跳转,header信息);
36 // 跳转地址未设置时 默认返回上一个页面
37 $this->success('跳转成功',url('index/index'));
38
39 }else{
40 // 失败之后跳转
41
42 $this->error('登录失败');
43 }
44 }
45
46
47 // 重定向
48
49 public function cdx(){
50
51 $this->redirect('index/index',['id'=>100,'name'=>'abc']);
52 }
53
54 // 空操作
55
56 public function _empty(){
57 $this->redirect('index/index');
58
59 }
60 }


19、19行中的加载登录页面加载的就是view中的login中的index.html

42、默认跳转时上一个页面

 

视图中的login文件夹中的index.html



1 <!doctype html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <title>Document</title>
6 </head>
7 <body>
8 <form action="{:url('check')}" method="post">
9 <h3>用户登录页面</h3>
10 <p>
11 User: <input type="text" name="username" id="">
12 </p>
13 <p>
14 Pass: <input type="password" name="password" id="">
15 </p>
16 <p>
17 <input type="submit" value="登录">
18 <input type="reset" value="注册">
19 </p>
20 </form>
21 </body>
22 </html>


8、第8行ur方式找到控制器中的check函数l