thinkphp 响应

 2023-09-18 阅读 28 评论 0

摘要:响应是由 think\Response 类或者子类完成 响应输出 <?phpnamespace app\index\controller;use think\exception\ValidateException; use think\facade\Request; class Index extends BaseController {/*** 显示资源列表** @return \think\Response*/public function in

响应是由 think\Response 类或者子类完成

响应输出

<?phpnamespace app\index\controller;use think\exception\ValidateException;
use think\facade\Request;
class Index extends BaseController
{/*** 显示资源列表** @return \think\Response*/public function index(){$data = 'ming';return response($data);}/*** 显示创建资源表单页.** @return \think\Response*/public function create(){//}/*** 保存新建的资源** @param  \think\Request  $request* @return \think\Response*/public function save(Request $request){//}/*** 显示指定的资源** @param  int  $id* @return \think\Response*/public function read($id){//}/*** 显示编辑资源表单页.** @param  int  $id* @return \think\Response*/public function edit($id){//}/*** 保存更新的资源** @param  \think\Request  $request* @param  int  $id* @return \think\Response*/public function update(Request $request, $id){//}/*** 删除指定资源** @param  int  $id* @return \think\Response*/public function delete($id){//}public function __call($name, $arguments){// TODO: Implement __call() method.return 'error request';}
}
<?phpnamespace app\index\controller;use think\exception\ValidateException;
use think\facade\Request;
class Index extends BaseController
{/*** 显示资源列表** @return \think\Response*/public function index(){$data = 'ming';return response($data);}/*** 显示创建资源表单页.** @return \think\Response*/public function create(){//}/*** 保存新建的资源** @param  \think\Request  $request* @return \think\Response*/public function save(Request $request){//}/*** 显示指定的资源** @param  int  $id* @return \think\Response*/public function read($id){//}/*** 显示编辑资源表单页.** @param  int  $id* @return \think\Response*/public function edit($id){//}/*** 保存更新的资源** @param  \think\Request  $request* @param  int  $id* @return \think\Response*/public function update(Request $request, $id){//}/*** 删除指定资源** @param  int  $id* @return \think\Response*/public function delete($id){//}public function __call($name, $arguments){// TODO: Implement __call() method.return 'error request';}
}

响应参数

链式处理

重定向

使用redirect助手函数重定向
访问 http://localhost:8082/index.php/index/index/ 重定向到 http://localhost:8082/index.php/index/index/hello.html

    /*** 显示资源列表** @return \think\Response*/public function index(){return redirect('hello')->with('name', 'thinkphp');}public function hello(){$name = session('name');return  'hello' . $name;}

thinkphp中间件?传参使用params传入

文件下载

public function download()
{$data = '这是一个测试文件';return download($data, 'test.txt', true);
}

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/74671.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息