7——ThinkPhp中的响应和重定向:

 public function index3(){
        //响应数据:
        $data=['title'=>"标题部分","content"=>"内容部分"];
        //return json($data);
        //return json($data,201);
        //return xml($data);
        //请求信息给模板:
        $this->assign('name','xiaoming222');
        return $this->fetch('index2/index');
    }
    //
    public function hello(){
        return "跳转过来的页面333";
    }
    //页面跳转
    public function hello3(){
        //$this->success('正确的页面跳转','hello');
        //携带参数进行跳转:
        //$this->error('错误提示页面跳转','/index/index/url2.html?name=xiaoming');
        //重定向:
        $this->redirect('http://www.baidu.com');
    }

  

原文地址:https://www.cnblogs.com/yiweiyihang/p/8849222.html