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.每个控制器必须添加空操作

猜你喜欢

转载自www.cnblogs.com/SSs1995/p/9420578.html
今日推荐