PHP 中TP5 Request 請求物件的方法

墨辰丷
發布: 2023-03-26 17:50:02
原創
2187 人瀏覽過

這篇文章主要介紹了PHP 中TP5 Request 請求對象的實例詳解的相關資料,這裡提供實現代碼幫助大家理解這部分內容,需要的朋友可以參考下

PHP 中TP5 Request 請求物件

public/index.php

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

 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(&#39;name&#39;, &#39;onestopweb&#39;); 
    //cookie(&#39;email&#39;, &#39;onestopweb@163.com&#39;); 
    //session(null); 
    //cookie(&#39;email&#39;,null); 
    dump($request->session()); 
    dump($request->cookie()); 
     
    dump($request->param(&#39;type&#39;)); 
    dump($request->cookie(&#39;email&#39;)); 
     
    # 获取模块 控制器 操作 
    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.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!