ホームページ  >  記事  >  バックエンド開発  >  PHPにおけるTP5 Requestリクエストオブジェクトのメソッド

PHPにおけるTP5 Requestリクエストオブジェクトのメソッド

墨辰丷
墨辰丷オリジナル
2018-05-18 17:09:442165ブラウズ

この記事では、PHP での TP5 リクエスト リクエスト オブジェクトの詳細な例に関する関連情報を主に紹介します。実装コードは、この部分の内容を理解するのに役立つようにここに提供されています

TP5 リクエスト リクエスト。 PHP のオブジェクト

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;;

appindexcontrollerIndex.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.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リクエストライブラリでsocks5プロキシをエンコードする問題を解決する

Python3リクエストでIPプロキシプールを使用してIPをランダムに生成するインスタンス

Pythonリクエストのプロキシインスタンスに基づく図書館

以上がPHPにおけるTP5 Requestリクエストオブジェクトのメソッドの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。