• \n    \n    \n        

    \n            賬號:\n        <\/p>\n        

    \n            密碼:\n        <\/P>\n        

    \n            \n            \n        <\/p>\n    <\/form>\n<\/body>\n<\/html><\/pre>

    2. Create a new login controller<\/p>

    namespace app\\index\\controller;\nuse think\\Controller;\n\/\/繼承Controller\nclass Login extends Controller\n{\n    public function index(){\n        return view();\n    }\n\/\/    判斷登陸成功失敗的邏輯\n    public function check(){\n        $user=$_POST['username'];\n        $pwd=$_POST['password'];\n        if($user=='admin' && $pwd=='123'){\n\/\/            如果成功則跳到index\/index頁面\n            $this->success('登陸成功',url('\/index\/index'));\n        }else{\n            $this->error('登陸失敗');\n        }\n    }\n}<\/pre>

    System success method description<\/p>

     \/**\n     * 操作成功跳轉(zhuǎn)的快捷方法\n     * @access protected\n     * @param mixed  $msg    提示信息\n     * @param string $url    跳轉(zhuǎn)的 URL 地址\n     * @param mixed  $data   返回的數(shù)據(jù)\n     * @param int    $wait   跳轉(zhuǎn)等待時間\n     * @param array  $header 發(fā)送的 Header 信息\n     * @return void\n     * @throws HttpResponseException\n     *\/\n    protected function success($msg = '', $url = null, $data = '', $wait = 3, array $header = [])\n    {}<\/pre>

    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<\/p>

    \"How<\/p>

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

    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<\/p>

    \/\/ 默認(rèn)跳轉(zhuǎn)頁面對應(yīng)的模板文件\n    'dispatch_success_tmpl'  => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',    \/\/成功跳轉(zhuǎn)的界面\n    'dispatch_error_tmpl'    => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',    \/\/失敗跳轉(zhuǎn)的界面<\/pre>

    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 <\/p>

    and then modify the code of the file. I will post the key information below <\/p>

    \n        \n            \n            

    :)<\/h1>\n            \n            \"How\n            

    <\/p>\n            \n            \n            

    :(<\/h1>\n            \n            \"How\n            

    <\/p>\n            \n        <\/pre>

    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<\/p>

    \/\/原來指定的路徑\n\/\/ 默認(rèn)跳轉(zhuǎn)頁面對應(yīng)的模板文件\n    'dispatch_success_tmpl'  => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',\n    'dispatch_error_tmpl'    => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl'\n\/\/修改為自定義的文件路徑\n     'dispatch_success_tmpl'  => THINK_PATH . 'tpl' . DS . 'success.tpl',\n     'dispatch_error_tmpl'    => THINK_PATH . 'tpl' . DS . 'error.tpl'<\/pre>

    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<\/p>\n

    Recommended learning: \"thinkPHP Video Tutorial<\/a>\"<\/p>"}

    亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

    Home PHP Framework ThinkPHP How to jump to the current page in thinkphp

    How to jump to the current page in thinkphp

    Dec 12, 2022 am 09:21 AM
    thinkphp

    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

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <title>登陸</title>
    </head>
    <body>
        <!--{:url(&#39;check&#39;)}  :提交到本頁面的控制器下的check方法-->
        <form action="{:url(&#39;check&#39;)}" method="post">
            <p>
                賬號:<input type="text" name="username" id="username">
            </p>
            <P>
                密碼:<input type="text" name="password" id="password">
            </P>
            <p>
                <input type="submit" value="提交">
                <input type="reset" value="重置">
            </p>
        </form>
    </body>
    </html>

    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[&#39;username&#39;];
            $pwd=$_POST[&#39;password&#39;];
            if($user==&#39;admin&#39; && $pwd==&#39;123&#39;){
    //            如果成功則跳到index/index頁面
                $this->success(&#39;登陸成功&#39;,url(&#39;/index/index&#39;));
            }else{
                $this->error(&#39;登陸失敗&#39;);
            }
        }
    }

    System success method description

     /**
         * 操作成功跳轉(zhuǎn)的快捷方法
         * @access protected
         * @param mixed  $msg    提示信息
         * @param string $url    跳轉(zhuǎn)的 URL 地址
         * @param mixed  $data   返回的數(shù)據(jù)
         * @param int    $wait   跳轉(zhuǎn)等待時間
         * @param array  $header 發(fā)送的 Header 信息
         * @return void
         * @throws HttpResponseException
         */
        protected function success($msg = &#39;&#39;, $url = null, $data = &#39;&#39;, $wait = 3, array $header = [])
        {}

    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

    // 默認(rèn)跳轉(zhuǎn)頁面對應(yīng)的模板文件
        &#39;dispatch_success_tmpl&#39;  => THINK_PATH . &#39;tpl&#39; . DS . &#39;dispatch_jump.tpl&#39;,    //成功跳轉(zhuǎn)的界面
        &#39;dispatch_error_tmpl&#39;    => THINK_PATH . &#39;tpl&#39; . DS . &#39;dispatch_jump.tpl&#39;,    //失敗跳轉(zhuǎn)的界面

    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

    <!--根據(jù)code來判斷顯示成功還是失敗,1代表成功,0代表失敗-->
            <?php switch ($code) {?>
                <?php case 1:?>
                <h1>:)</h1>
                <!--這行代碼是我自己在static下添加的一張成功的笑臉圖片,路徑是根據(jù)入口文件的位置來定義圖片的位置,入口文件和static是同一級目錄-->
                <img  src="/static/imghw/default1.png"  data-src="/static/xiao.jpg"  class="lazy"      style="max-width:90%" height="100px" alt="How to jump to the current page in thinkphp" >
                <p><?php echo(strip_tags($msg));?></p>
                <?php break;?>
                <?php case 0:?>
                <h1>:(</h1>
                <!--這行代碼是我自己在static下添加的一張失敗的哭臉圖片,路徑是根據(jù)入口文件的位置來定義圖片的位置,入口文件和static是同一級目錄-->
                <img  src="/static/imghw/default1.png"  data-src="/static/ku.jpg"  class="lazy"      style="max-width:90%" height="100px" alt="How to jump to the current page in thinkphp" >
                <p><?php echo(strip_tags($msg));?></p>
                <?php break;?>
            <?php } ?>

    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

    //原來指定的路徑
    // 默認(rèn)跳轉(zhuǎn)頁面對應(yīng)的模板文件
        &#39;dispatch_success_tmpl&#39;  => THINK_PATH . &#39;tpl&#39; . DS . &#39;dispatch_jump.tpl&#39;,
        &#39;dispatch_error_tmpl&#39;    => THINK_PATH . &#39;tpl&#39; . DS . &#39;dispatch_jump.tpl&#39;
    //修改為自定義的文件路徑
         &#39;dispatch_success_tmpl&#39;  => THINK_PATH . &#39;tpl&#39; . DS . &#39;success.tpl&#39;,
         &#39;dispatch_error_tmpl&#39;    => THINK_PATH . &#39;tpl&#39; . DS . &#39;error.tpl&#39;

    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!

    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 admin@php.cn

    Hot AI Tools

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Hot Topics

    PHP Tutorial
    1488
    72
    How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

    To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

    There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

    ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

    How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

    Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

    Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

    Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

    How to install thinkphp How to install thinkphp Apr 09, 2024 pm 05:42 PM

    ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

    How is the performance of thinkphp? How is the performance of thinkphp? Apr 09, 2024 pm 05:24 PM

    ThinkPHP is a high-performance PHP framework with advantages such as caching mechanism, code optimization, parallel processing and database optimization. Official performance tests show that it can handle more than 10,000 requests per second and is widely used in large-scale websites and enterprise systems such as JD.com and Ctrip in actual applications.

    Development suggestions: How to use the ThinkPHP framework for API development Development suggestions: How to use the ThinkPHP framework for API development Nov 22, 2023 pm 05:18 PM

    Development suggestions: How to use the ThinkPHP framework for API development. With the continuous development of the Internet, the importance of API (Application Programming Interface) has become increasingly prominent. API is a bridge for communication between different applications. It can realize data sharing, function calling and other operations, and provides developers with a relatively simple and fast development method. As an excellent PHP development framework, the ThinkPHP framework is efficient, scalable and easy to use.

    Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks Nov 22, 2023 pm 12:01 PM

    "Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

    See all articles