The following tutorial column of thinkphp framework will introduce to you three methods of obtaining parameters in ThinkPHP6. I hope it will be helpful to friends in need!
First type: dependency injection
dump($ this->request->param());//All parameters, return arrayarray:1 [ "name" => "1" ]dump($this->request->param('id'));//Specific parameters , returns the string dump($this->request->get('id'));//Only valid for type B urldump($this-> request->param('name','aaa'));//If no name parameter is passed, set the default value and return the string aaadump($this->request->param ('name','1','intval')); Convert the received parameters to integer type. Type A URL returns the default value 1, type C URL returns 12, and type D URL returns 0
Second: Use the helper function
var_dump(input('id'));//Both Class A url and Class B url return string 1. If Class C url and Class D url are not passed, NULL will be returnedThe third method: static acquisition
Introduce use think\facade\Request;before use
Check whether the variable is set: Request::has('id','get');Both class A url and class B url return true, class C url and class D url return falseRequest::has('name','post'); Check whether there is a posted name and return true or false Request::param('name');// Get The name variable of the current request, returns a string, does not pass the output nullRequest::param(); // Get all variables of the current request (filtered)Request::param( false);//Get all unfiltered variables of the current requestRequest::param(['name', 'email']);//Get some variablesFinally:
In addition, in some cases, we also need to determine what the request is, For example:if($request->isPost()){ //判断是否是post请求}Similar situations are
The above are the various ways to obtain parameters in ThinkPHP6. It may not be comprehensive, but mastering these can basically satisfy the parameter acquisition in most situations...
The above is the detailed content of Three methods of obtaining parameters in ThinkPHP6. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
