5ucms论坛
标题:
6 thinkphp响应 response
[打印本页]
作者:
admin
时间:
2019-5-29 18:47
标题:
6 thinkphp响应 response
返回输出的内容
public function hello2(){
$data = ['name'=>'thinkphp','status'=>'1'];
//以下为举例,实际上只能returng一次
return print_r($data); //数组
return json($data); //返回json格式
return json($data,201); //网页状态码默认是200,这样可以改成201
return xml($data); //返回xml格式
$this->assign('name','渲染 模板');//设置一个name值
return $this->fetch('index/index2');//使用另一个控制器的模板
}
复制代码
页面跳转
public function hello3(){
$this->success('正确!','hello') ; //提示正确后跳转到本控制器下的hello的方法里
$this->error('错误','/admin/index.html'); //提示错误后跳转
//以上2个第二个参数可以不填,默认返回原页面
$this->redirect('http://www.5ucms.com'); //直接跳转到某网址,这里填网址即可
}
复制代码
欢迎光临 5ucms论坛 (http://bbs.5ucms.com/)
Powered by Discuz! X3.2