响应是由 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);
}
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态