PHP 中TP5 Request 请求对象的实例详解


Posted in PHP onJuly 31, 2017

PHP 中TP5 Request 请求对象

public/index.php

<?php 
 
// [ 应用入口文件 ] 
// 定义应用目录 
define('APP_PATH', __DIR__ . '/../app/'); 
 
// 定义配置文件目录和应用目录同级 
define('CONF_PATH', __DIR__.'/../config/'); 
 
// 加载框架引导文件 
require __DIR__ . '/../thinkphp/start.php';

 app\index\controller\Index.php

<?php 
namespace app\index\controller; 
use think\Request; 
class Index 
{ 
  public function index(Request $request) 
  { 
    # 获取浏览器输入框的值 
    dump($request->domain()); 
    dump($request->pathinfo()); 
    dump($request->path()); 
     
    # 请求类型 
    dump($request->method()); 
    dump($request->isGet()); 
    dump($request->isPost()); 
    dump($request->isAjax()); 
     
    # 请求的参数 
    dump($request->get()); 
    dump($request->param()); 
    dump($request->post()); 
    //session('name', 'onestopweb'); 
    //cookie('email', 'onestopweb@163.com'); 
    //session(null); 
    //cookie('email',null); 
    dump($request->session()); 
    dump($request->cookie()); 
     
    dump($request->param('type')); 
    dump($request->cookie('email')); 
     
    # 获取模块 控制器 操作 
    dump($request->module()); 
    dump($request->controller()); 
    dump($request->action()); 
     
    # 获取URL 
    dump($request->url()); 
    dump($request->baseUrl()); 
  } 
}

 地址栏输入的链接:http://192.168.0.180:55/index/index/index.html?name=chaoyi&type=blog

string(23) "http://192.168.0.180:55" 
string(22) "index/index/index.html" 
string(17) "index/index/index" 
string(3) "GET" 
bool(true) 
bool(false) 
bool(false) 
array(2) { 
 ["name"] => string(6) "chaoyi" 
 ["type"] => string(4) "blog" 
} 
array(2) { 
 ["name"] => string(6) "chaoyi" 
 ["type"] => string(4) "blog" 
} 
array(0) { 
} 
array(1) { 
 ["name"] => string(10) "onestopweb" 
} 
array(3) { 
 ["username"] => string(6) "chaoyi" 
 ["PHPSESSID"] => string(26) "nugcsr2j9krr2lhk8bntggl412" 
 ["email"] => string(18) "onestopweb@163.com" 
} 
string(4) "blog" 
string(18) "onestopweb@163.com" 
string(5) "index" 
string(5) "Index" 
string(5) "index" 
string(45) "/index/index/index.html?name=chaoyi&type=blog" 
string(23) "/index/index/index.html"

 以上就是PHP 中TP5 Request 请求对象的实例如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

PHP 相关文章推荐
php Ubb代码编辑器函数代码
Jul 05 PHP
php中DOMElement操作xml文档实例演示
Mar 26 PHP
使用php get_headers 判断URL是否有效的解决办法
Apr 27 PHP
Zend的Registry机制的使用说明
May 02 PHP
PHP随机生成唯一HASH值自定义函数
Apr 20 PHP
PHP请求Socket接口测试实例
Aug 12 PHP
php 多文件上传的实现实例
Oct 23 PHP
Laravel中的chunk组块结果集处理与注意问题
Aug 15 PHP
PHP实现字符串的全排列详解
Apr 24 PHP
PHP判断函数是否被定义的方法
Jun 21 PHP
Laravel 5+ .env环境配置文件详解
Apr 06 PHP
PHPstorm激活码2020年5月13日亲测有效
Sep 17 PHP
PHP将数据导出Excel表中的实例(投机型)
Jul 31 #PHP
浅谈thinkphp5 instance 的简单实现
Jul 30 #PHP
PHP用PDO如何封装简单易用的DB类详解
Jul 30 #PHP
详解PHP防止直接访问.php 文件的实现方法
Jul 28 #PHP
php简单实现单态设计模式的方法分析
Jul 28 #PHP
[原创]PHP实现SQL语句格式化功能的方法
Jul 28 #PHP
使用php自动备份数据库表的实现方法
Jul 28 #PHP
You might like
PHP加速 eAccelerator配置和使用指南
2009/06/05 PHP
完美解决PHP中文乱码
2009/11/26 PHP
PHP反射类ReflectionClass和ReflectionObject的使用方法
2013/11/13 PHP
PHP使用ActiveMQ实例
2018/02/05 PHP
Using the TextRange Object
2006/10/14 Javascript
Javascript 错误处理的几种方法
2009/06/13 Javascript
jquery 框架使用教程 AJAX篇
2009/10/11 Javascript
onclick与listeners的执行先后问题详细解剖
2013/01/07 Javascript
js之事件冒泡和事件捕获详细介绍
2013/10/28 Javascript
Javascript模拟加速运动与减速运动代码分享
2014/12/11 Javascript
javascript实现图片跟随鼠标移动效果的方法
2015/05/13 Javascript
AngularJS中的$watch(),$digest()和$apply()区分
2016/04/04 Javascript
JS模仿腾讯图片站的图片翻页按钮效果完整实例
2016/06/21 Javascript
jQuery插件echarts实现的多折线图效果示例【附demo源码下载】
2017/03/04 Javascript
vue组件之Alert的实现代码
2017/10/17 Javascript
移动web开发之touch事件实例详解
2018/01/17 Javascript
Vue打包后出现一些map文件的解决方法
2018/02/13 Javascript
Vue弹出菜单功能的实现代码
2018/09/12 Javascript
在vue项目中引用Iview的方法
2018/09/14 Javascript
JS中使用cavas截图网页并解决跨域及模糊问题
2018/11/13 Javascript
Vue核心概念Action的总结
2019/01/18 Javascript
微信小程序bindinput与bindsubmit的区别实例分析
2019/04/17 Javascript
[04:03][TI9趣味短片] 小鸽子茶话会
2019/08/20 DOTA
Python实现对excel文件列表值进行统计的方法
2015/07/25 Python
Python实现包含min函数的栈
2016/04/29 Python
python实现画圆功能
2018/01/25 Python
python pandas 对时间序列文件处理的实例
2018/06/22 Python
python使用wxpy轻松实现微信防撤回的方法
2019/02/21 Python
pyqt5实现按钮添加背景图片以及背景图片的切换方法
2019/06/13 Python
Shell如何接收变量输入
2016/08/06 面试题
MVC的各个部分都有那些技术来实现?如何实现?
2016/04/21 面试题
平面设计自荐信
2013/10/07 职场文书
计算机应用毕业生自荐信
2013/10/23 职场文书
机械工程及自动化专业求职信
2014/09/03 职场文书
副总经理岗位职责
2015/02/02 职场文书
《青山不老》教学反思
2016/02/22 职场文书