tp5頁面跳轉,空控制器空方法


    namespace app\index\controller;
    use think\Controller;
    class Login extends Controller{
        //顯示html頁面
        public function login(){
            return view();
        }
        public function check(){
            $uid = $_POST['uid'];
            $pwd = $_POST['pwd'];
            if($uid == 'admin' && $pwd == '123'){
                //參數:返回的信息,成功后跳轉的url,返回數據,等待時間,頭信息
                $this->success('成功','admin/deer/grass','','5');
            }else{
//                $this->error();
                $this->redirect('admin/deer/grass',['id'=>100,'name'=>'abc']);
            }
        }
        //對空方法的重定向
        public function _empty(){
            $this->redirect('admin/deer/grass',['id'=>12]);
        }
    }
        <form action="{:url('check')}" method="post">
            <p>
                賬號:<input type="text" name="uid" />
            </p>
            <p>
                密碼:<input type="password" name="pwd" />
            </p>
            <p>
                <input type="submit" value="提交" />
            </p>
        </form>

 

 

以登錄頁面為例,index模塊下,login控制器,login方法跳轉html頁面

登錄的html中寫有賬號密碼的form表單,跳轉路徑為login控制器的check方法

控制器中調用Controller控制器,繼承success,error方法,並提交參數。

則點擊提交按鈕可進行頁面跳轉

 

空方法重定向:

  調用Controller控制器,繼承redirect方法,參數為 地址url,傳值。

  設置成功后則地址欄方法若輸入不正確則跳轉參數規定的頁面。

空控制器重定向:

  新建Error控制器 

    namespace app\index\controller;
    use think\Controller;
    class Error extends Controller{
        public function _empty(){
            $this->redirect('Rabit/carrot');
        }
    }

  則地址欄控制器部分輸入不正確跳轉參數規定的頁面。

注意:

  1.跳轉路徑寫法‘{:url()}’

  2.每個控制器必須添加空操作


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM