isPost()"."> How does thinkphp5 determine whether it is a post request?-ThinkPHP-php.cn
Home> PHP Framework> ThinkPHP> body text

How does thinkphp5 determine whether it is a post request?

WBOY
Release: 2022-04-25 11:42:16
Original
5022 people have browsed it

在thinkphp5中,可以利用isPost()方法判断是否是post请求,该方法的作用就是判断当前是否为Post提交数据的,结果若为true则判断是post请求,若为false则不是post请求,语法为“$this->isPost()”。

How does thinkphp5 determine whether it is a post request?

本文操作环境:Windows10系统、ThinkPHP5版、Dell G3电脑。

thinkphp5怎么判断是否是post请求

ThinkPHP中使用isPost()方法来判断当前是否为Post提交数据的。

如果我在做一个添加用户的操作时,我们可以设置一个User/useradd.html作为模板。然后写一个UserAction.php。在UserAction.php中写一个userAdd方法,使用isPost()来判断是否状态,就可以把提交前和提交后写在一个Action里面了。

//用户添加 public function userAdd(){
Copy after login
if($this->isPost()){ //处理 } else{ $this->display('userAdd'); } }
Copy after login

How does thinkphp5 determine whether it is a post request?

之前使用3.2版本时,经常会使用到

if(IS_POST){ }else{ }
Copy after login

在thinkphp5.1中,废除了IS_POST。

thinkphp5.1中,我们可以这样用,

控制器中引入

use think\facade\Request;
Copy after login
public function index() { if(Request::isPost()){ //这样判断 } else { } }
Copy after login

推荐学习:《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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!