ThinkPHP5.1 闭包路由 直接输出数据 不需要定义控制器
2017-12-02 12:47
495 查看
# /home/myth/www/think/route/route.php
Route::get('hello', function () {
return 'hello,world!';
}); // http://contoso.org/hello 闭包路由
Route::get('hello/:name', function ($name) {
return 'Hello,' . $name;
}); // http://contoso.org/hello/jack 闭包路由定义支持参数传递
Route::rule('hi/:name', function (think\Request $request, $name) {
$method = $request->method();
return '[' . $method . '] Hi,' . $name;
}); // http://contoso.org/hi/jack 闭包中使用依赖注入$request
Route::get('print/:name', function (think\Response $response, $name) {
return $response
->data('Print,' . $name)
->code(200)
->contentType('text/plain');
}); // http://contoso.org/print/jack 在路由闭包中指定响应对象输出
Route::get('hello', function () {
return 'hello,world!';
}); // http://contoso.org/hello 闭包路由
Route::get('hello/:name', function ($name) {
return 'Hello,' . $name;
}); // http://contoso.org/hello/jack 闭包路由定义支持参数传递
Route::rule('hi/:name', function (think\Request $request, $name) {
$method = $request->method();
return '[' . $method . '] Hi,' . $name;
}); // http://contoso.org/hi/jack 闭包中使用依赖注入$request
Route::get('print/:name', function (think\Response $response, $name) {
return $response
->data('Print,' . $name)
->code(200)
->contentType('text/plain');
}); // http://contoso.org/print/jack 在路由闭包中指定响应对象输出
相关文章推荐
- ThinkPHP5.1 数据库查询数据 定义淘宝风格的路由URL
- ThinkPHP5.1 不需要控制器的路由 \类的命名空间\类名::静态方法名
- ThinkPHP5.1 多级控制器路由
- thinkphp的M方法可以直接使用模型类进行查询,而模型类名字要与数据表对应,模型类中字段不需要写
- ThinkPHP5.1 不需要控制器的路由 \类的命名空间\类名@方法名
- CodeIgniter_2 路由中定义伪静态 直接映射到相关的控制器
- 在ASP.NET中将数据直接输出成Excel格式
- Wex5案例使用JSON传输Thinkphp后端对接,以达成数据正常输出
- ThinkPHP5.1 路由地址中组合变量规则的使用
- 如何在控制器获取数据库的数据并且在模板输出
- 【C语言】终端一检测到输入后直接输出,不需要按下enter键
- 对Xml的文件操作,根据数据的配置和数据样式的定义,将结果字符输出
- thinkphp 模板格式化输出datetime类型数据
- 在ASP.NET中将数据直接输出成Excel内容
- thinkphp 3.2控制器绑定改变路由
- 2016/05/10 thinkphp 3.2.2 ①系统常量信息 ②跨控制器调用 ③连接数据库配置及Model数据模型层 ④数据查询
- DataSet中直接导出XML数据并且写到HTTP输出流中
- 定义职工类Employee对象数组,内放5个职工的数据(编号、姓名、性别、月薪),建立函数输出职工信息表。
- Tomcat8.x 路由表的建立->路由的匹配->Servlet的执行->数据的输出
- 不需要存入文件,直接将获取的数据转换成甘特图所需的数据格式并显示