在thinkphp5中,可以利用isPost()方法判断是否是post请求,该方法的作用就是判断当前是否为Post提交数据的,结果若为true则判断是post请求,若为false则不是post请求,语法为“$this->isPost()”。
本文操作环境:Windows10系统、ThinkPHP5版、Dell G3电脑。
thinkphp5怎么判断是否是post请求
ThinkPHP中使用isPost()方法来判断当前是否为Post提交数据的。
如果我在做一个添加用户的操作时,我们可以设置一个User/useradd.html作为模板。然后写一个UserAction.php。在UserAction.php中写一个userAdd方法,使用isPost()来判断是否状态,就可以把提交前和提交后写在一个Action里面了。
//用户添加 public function userAdd(){
if($this->isPost()){ //处理 } else{ $this->display('userAdd'); } }
之前使用3.2版本时,经常会使用到
if(IS_POST){ }else{ }
在thinkphp5.1中,废除了IS_POST。
thinkphp5.1中,我们可以这样用,
控制器中引入
use think\facade\Request;
public function index() { if(Request::isPost()){ //这样判断 } else { } }
推荐学习:《PHP视频教程》
The above is the detailed content of How does thinkphp5 determine whether it is a post request?. 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

SublimeText3 Linux new version
SublimeText3 Linux latest version

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.

Zend Studio 13.0.1
Powerful PHP integrated development environment

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

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
