首页 >后端开发 >php教程 > 正文

PHP 中TP5 Request 请求对象的方法

原创2018-05-18 17:09:4401073
这篇文章主要介绍了PHP 中TP5 Request 请求对象的实例详解的相关资料,这里提供实现代码帮助大家理解这部分内容,需要的朋友可以参考下

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 请求对象的实例如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家!

相关推荐:

解决Python requests库编码 socks5代理的问题

python3 requests中使用ip代理池随机生成ip的实例

基于python requests库中的代理实例

以上就是PHP 中TP5 Request 请求对象的方法的详细内容,更多请关注php中文网其它相关文章!

php中文网最新课程二维码

声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理

  • 相关标签:Request php 方法
  • 相关文章

    相关视频


    网友评论

    文明上网理性发言,请遵守 新闻评论服务协议

    我要评论
  • 专题推荐

    推荐视频教程
  • javascript初级视频教程javascript初级视频教程
  • jquery 基础视频教程jquery 基础视频教程
  • 视频教程分类