请求对象(request对象)
用户--------》request对象------》$_GET||$_POST||$_REQUEST||$_COOKIE||$_FILES
用户<-----response-----》json /xml/view模板输出
json在真实项目中


返回json格式数据:
这就是我们在公司写业务代码返回json数据

首页json数据,我这里大概展示一下。


"body": {
"data": {
"adList": [
{
"ADTitle": "丝路贵人商城",
"AdHttp": "WxPages/productList.html?keyword=",
"AdNum": "1",
"BackColor": "#000000",
"BeginDate": "2017-12-07T15:33:17",
"Descript": "共享电商平台",
"EndDate": "2021-12-07T15:33:20",
"FloorType": " ",
"MaxUseSpePow": 0.0000,
"ModuType": "1",
"OriginPrice": 0.0000,
"PicturePath": "/upload/user/2017/12/2017/M1052/品牌特卖/bananer/1.png",
"PreSpePower": 0.0000,
"ResVersion": 1,
"ShopPrice": 0.0000,
"StaType": "V",
"SysAdClass_ID": 1064,
"SysAdPlace_ID": 1344,
"SysAd_ID": 5515,
"Title": "首页轮播层"
},
{
"ADTitle": "丝路贵人商城",
"AdHttp": "WxPages/productList.html?keyword=",
"AdNum": "1",
"BackColor": "#000000",
"BeginDate": "2017-12-07T15:35:18",
"Descript": "共享电商平台",
"EndDate": "2019-12-19T15:35:21",
"FloorType": " ",
"MaxUseSpePow": 0.0000,
"ModuType": "1",
"OriginPrice": 0.0000,
"PicturePath": "/upload/user/2017/12/2017/M1052/品牌特卖/bananer/2.png",
"PreSpePower": 0.0000,
"ResVersion": 1,
"ShopPrice": 0.0000,
"StaType": "V",
"SysAdClass_ID": 1064,
"SysAdPlace_ID": 1344,
"SysAd_ID": 5516,
"Title": "首页轮播层"
},
{
"ADTitle": "vivo手机",
"AdHttp": "wxpages/productDetail.html?goods_id=148741",
"AdNum": "1",
"BeginDate": "2017-11-22T04:32:16",
"Descript": "新品首发",
"EndDate": "2018-11-30T04:32:20",
"FloorType": " ",
"ModuType": "1",
"PicturePath": "/upload/user/2017/11/2017/M1/banner图/banner-2.jpg",
"ResVersion": 1,
"StaType": "V",
"SysAdClass_ID": 1064,
"SysAdPlace_ID": 1344,
"SysAd_ID": 4442,
"Title": "首页轮播层"
},
{
"ADTitle": "iPhone8",
"AdHttp": "wxpages/productDetail.html?goods_id=140587",
"AdNum": "1",
"BackColor": "#000000",
"BeginDate": "2017-12-07T15:44:13",
"Descript": "新品首发",
"EndDate": "2019-12-07T15:44:15",
"FloorType": " ",
"MaxUseSpePow": 0.0000,
"ModuType": "1",
"OriginPrice": 0.0000,
"PicturePath": "/upload/user/2017/12/2017/M1056/微商城手机banner.jpg",
"PreSpePower": 0.0000,
"ResVersion": 1,
"ShopPrice": 0.0000,
"StaType": "V",
"SysAdClass_ID": 1064,
"SysAdPlace_ID": 1344,
"SysAd_ID": 5517,
"Title": "首页轮播层"
}
],
"cateList": [
{
"CateTitle": "美妆个护",
"Categories_ID": 2264,
"CreateDate": "2017-11-22T10:43:06.02",
"ModuType": "1",
"OrderBy": 1,
"ResVersion": 1,
"StaType": "V",
"SysAdClass_ID": 1064,
"Title": "首页轮播层",
"URL": "WxPages/productList.html?categoryID=2264"
},
{
"CateTitle": "服装城",
"Categories_ID": 2044,
"CreateDate": "2017-11-22T10:43:57.427",
"ModuType": "1",
"OrderBy": 2,
"ResVersion": 1,
"StaType": "V",
"SysAdClass_ID": 1064,
"Title": "首页轮播层",
"URL": "WxPages/productList.html?categoryID=2044"
},
{
"CateTitle": "户外运动",
"Categories_ID": 1876,
"CreateDate": "2017-11-22T10:44:24.773",
"ModuType": "1",
"OrderBy": 3,
"ResVersion": 1,
"StaType": "V",
"SysAdClass_ID": 1064,
"Title": "首页轮播层",
"URL": "WxPages/productList.html?categoryID=1876"
},
{
"CateTitle": "手机数码",
"Categories_ID": 1930,
"CreateDate": "2017-11-22T10:45:23.867",
"ModuType": "1",
"OrderBy": 4,
"ResVersion": 1,
"StaType": "V",
"SysAdClass_ID": 1064,
"Title": "首页轮播层",
"URL": "WxPages/productList.html?categoryID=1930"
},
{
"CateTitle": "电脑办公",
"Categories_ID": 1890,
"CreateDate": "2017-11-22T10:46:02.337",
"ModuType": "1",
"OrderBy": 5,
"ResVersion": 1,
"StaType": "V",
"SysAdClass_ID": 1064,
"Title": "首页轮播层",
"URL": "WxPages/productList.html?categoryID=1890"
},
{
"CateTitle": "美食街",
"Categories_ID": 2543,
"CreateDate": "2017-11-22T10:46:48.883",
"ModuType": "1",
"OrderBy": 6,
"ResVersion": 1,
"StaType": "V",
"SysAdClass_ID": 1064,
"Title": "首页轮播层",
"URL": "WxPages/productList.html?categoryID=2543"
},
{
"CateTitle": "箱包配饰",
"Categories_ID": 2378,
"CreateDate": "2017-11-22T10:47:14.417",
"ModuType": "1",
"OrderBy": 7,
"ResVersion": 1,
"StaType": "V",
"SysAdClass_ID": 1064,
"Title": "首页轮播层",
"URL": "WxPages/productList.html?categoryID=2378"
},
{
"CateTitle": "家居",
"Categories_ID": 1922,
"CreateDate": "2017-11-22T10:50:17.733",
"ModuType": "1",
"OrderBy": 7,
"ResVersion": 1,
"StaType": "V",
"SysAdClass_ID": 1064,
"Title": "首页轮播层",
"URL": "WxPages/productList.html?categoryID=1922"
}
],
"dTime": "2017/12/23 13:23:21",
"mType": "1",
"staType": "V",
"title": "首页轮播层"
}
},
"head": {
"TryIndex": 0,
"code": 10000,
"itemCount": 1,
"message": "图片信息获取成功"
}
}

例1 怎么使用request类和对象?
第一步 找到控制器你要写代码的位置,把request引进里面来

第二步 调用这个类的方法 $request = Request::instance();
第三步 输出结果看看对不对
echo $request->url(); // 获取当前URL地址 不含域名
如图所示

代码如下:
public function hello()
{
$request = Request::instance();
echo $request->url(); // 获取当前URL地址 不含域名
echo "<br/>";
}
输出网址:http://localhost:8989/php/mvc/TP5.0/public/admin/index4/hello

扩展部分:波利亚《怎样解题表》提出:“你以前见过它吗?你是否见过相同的问题而形式稍有不同?”想一想或搜一下百度你看是否还有别的法子达到这种效果?
提示: echo $this->request->url(); // 获取当前URL地址 不含域名
例2 request对象之绑定方法bind的使用
代码编写如下:
echo $this->request->bind('user_name','张三2222'); // 动态绑定属性
如图所示:

你能否检验这个论证这行代码?
在网址输入:http://localhost:8989/php/mvc/TP5.0/public/admin/index4/hello
输出结果如图所示:

例3 request对象之获取参数方法param()的使用
代码演示如下:
print_r($request->param());
结果如图所示:

习题1:试一试input方法。
习题2:试一试echo $request->param('en_name','jake','strtolower');看是不是输出以下图结果:
http://localhost:8989/php/mvc/TP5.0/public/admin/index4/hello.html?name=zhouxingzhi&en_name=%E5%91%A8%E8%A1%8C%E7%9F%A5

网友评论