ThinkPHP5.1 闭包路由 直接输出数据 不需要定义控制器
来源:互联网 发布:网络追逃人员查询系统 编辑:程序博客网 时间:2024/06/11 06:01
# /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 在路由闭包中指定响应对象输出
阅读全文
0 0
- ThinkPHP5.1 闭包路由 直接输出数据 不需要定义控制器
- ThinkPHP5.1 多级控制器路由
- ThinkPHP5.1 不需要控制器的路由 \类的命名空间\类名@方法名
- ThinkPHP5.1 不需要控制器的路由 \类的命名空间\类名::静态方法名
- ThinkPHP5 路由定义
- ThinkPHP5.1 数据库查询数据 定义淘宝风格的路由URL
- [ThinkPHP5.0] 2定义路由
- ThinkPHP5.1 @[模块/控制器/]操作
- ThinkPHP5.1 路由重定向
- ThinkPHP5 路由
- C++如何直接输出不需要缓存区
- thinkphp5 之数据操作和模板输出
- ThinkPHP5.1 action变量路由&controller变量路由
- 直接路由与非直接路由&直连路由静态路由动态路由的定义与区别
- thinkphp5 新建控制器
- [.NET]如何往WebBrowser里直接输出HTML?(不需要临时文件)
- 只写map不需要reduce,Mapper直接输出到mysql
- ThinkPHP5 路由模式
- sublime text安装及使用
- Java程序员的日常 —— Java类加载中的顺序
- Training set、Validation set and Testing set
- 血淋林的例子告诉你,为什么防“上传漏洞”要用白名单
- leetCode-Unique Paths
- ThinkPHP5.1 闭包路由 直接输出数据 不需要定义控制器
- eclipse和tomcat7相关配置问题
- ORACLE ROWNUM分页总结
- 1> python hello word
- JAVA程序员三年从入门到精通的视频资料
- Eclipse解决中文字体设置
- NOT EXISTS
- Find Pivot Index[Leetcode 724]
- 微信小程序——wx.navigateTo中url无法跳转问题(app.json中配置的tabBar与wx.navigateTo中url引用相同页面导致)(2017/12)