Home > PHP Framework > ThinkPHP > body text

How to jump to the current page in thinkphp

藏色散人
Release: 2022-12-12 09:21:28
Original
1993 people have browsed it

Thinkphp method to jump to the current page: 1. Create a new login.html page under index/login; 2. Create a new login controller; 3. Use "protected function success(){...} "Determine whether the jump is successful; 4. Open the "dispatch_jump.tpl" file; 5. Modify the configuration code under "config.php".

How to jump to the current page in thinkphp

The operating environment of this tutorial: Windows 7 system, ThinkPHP version 5, Dell G3 computer.

ThinkPHP5 page jump

Methods for page jump

First, you can use simple success and error methods to achieve it

1. Create a new login.html page under index/login




    
    登陆


    
    

账号:

密码:

Copy after login

2. Create a new login controller

namespace app\index\controller;
use think\Controller;
//继承Controller
class Login extends Controller
{
    public function index(){
        return view();
    }
//    判断登陆成功失败的逻辑
    public function check(){
        $user=$_POST['username'];
        $pwd=$_POST['password'];
        if($user=='admin' && $pwd=='123'){
//            如果成功则跳到index/index页面
            $this->success('登陆成功',url('/index/index'));
        }else{
            $this->error('登陆失败');
        }
    }
}
Copy after login

System success method description

 /**
     * 操作成功跳转的快捷方法
     * @access protected
     * @param mixed  $msg    提示信息
     * @param string $url    跳转的 URL 地址
     * @param mixed  $data   返回的数据
     * @param int    $wait   跳转等待时间
     * @param array  $header 发送的 Header 信息
     * @return void
     * @throws HttpResponseException
     */
    protected function success($msg = '', $url = null, $data = '', $wait = 3, array $header = [])
    {}
Copy after login

Jump successful The page effect: the success() method will have a waiting time interface, and then jump to /index/index, the error() method also has a waiting interface

How to jump to the current page in thinkphp

Modification The interface that shows successful login on the jump interface may not meet our needs, so we need to modify this template interface

1. To modify the template interface, first we need to find this template interface, open config.php and we can see There are the following two lines of code

// 默认跳转页面对应的模板文件
    'dispatch_success_tmpl'  => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',    //成功跳转的界面
    'dispatch_error_tmpl'    => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',    //失败跳转的界面
Copy after login

We can see from the above code that whether it is a successful jump or a failed jump, it is the same interface, dispatch_jump.tpl, we pass the directory thinkphp\tpl\dispatch_jump .tpl find this file

and then modify the code of the file. I will post the key information below


        
            
            

:)

How to jump to the current page in thinkphp

:(

How to jump to the current page in thinkphp

Copy after login

2. Modify the configuration file and change it to the interface written by yourself. We are in the thinkphp\tpl directory Create two new files, a success.tpl and an error.tpl file, modify the configuration code below config.php

//原来指定的路径
// 默认跳转页面对应的模板文件
    'dispatch_success_tmpl'  => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',
    'dispatch_error_tmpl'    => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl'
//修改为自定义的文件路径
     'dispatch_success_tmpl'  => THINK_PATH . 'tpl' . DS . 'success.tpl',
     'dispatch_error_tmpl'    => THINK_PATH . 'tpl' . DS . 'error.tpl'
Copy after login

bootstrap is a very excellent front-end framework, and many effects have been written in it to allow us to Calls, such as carousels, navigation bars, etc., and mobile terminal adaptation is given priority

Recommended learning: "thinkPHP Video Tutorial"

The above is the detailed content of How to jump to the current page in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!