thinkphp5的get和post数据封装的方法介绍(代码)
本篇文章给大家带来的内容是关于thinkphp5的get和post数据封装的方法介绍(代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
thinkphp5的get和post数据封装
一、view(html页面获取数据)
二、控制器
一、view(html页面获取数据)
<form action="index"> <input type="text" name="status" value="{$where.nireid}" placeholder="状态" > <input type="text" name="atype" value="{$where.atype}" placeholder="类型" > <input type="text" name="nireid" value="{$where.nireid}" placeholder="昵称" > <button type="submit" > 搜索</button> </form>
二、控制器
1、正常情况下我们是这样操作的
public function index(){ $where['status'] =input('get.status'); $where['atype'] =input('get.atype'); $where['nireid'] =input('get.nireid'); $this->assign('where',$where); $this->assign(UserExtractModel::systemPage($where)); return $this->fetch(); }
2、其实我们可以这样做
public function index(){ $where = self::getMore([ ['status',''], ['atype',''], ['nireid',''], ],$this->request); $this->assign('where',$where); $this->assign(UserExtractModel::systemPage($where)); return $this->fetch(); } public function getMore($params,Request $request=null,$suffix = false){ if($request === null) $request = Request::instance(); $p = []; $i = 0; foreach ($params as $param){ if(!is_array($param)) { $p[$suffix == true ? $i++ : $param] = $request->get($param); }else{ if(!isset($param[1])) $param[1] = null; if(!isset($param[2])) $param[2] = ''; $name = is_array($param[1]) ? $param[0].'/a' : $param[0]; $p[$suffix == true ? $i++ : (isset($param[3]) ? $param[3] : $param[0])] = $request->get($name,$param[1],$param[2]); } } return $p; }
(不要忘记use think\Request;)
(post同理)
以上是thinkphp5的get和post数据封装的方法介绍(代码)的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

宝塔部署thinkphp5报错的解决办法:1、打开宝塔服务器,安装php pathinfo扩展并启用;2、配置“.access”文件,内容为“RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L]”;3、在网站管理里面,启用thinkphp的伪静态即可。

thinkphp5 url重写不行的解决办法:1、查看httpd.conf配置文件中是否加载了mod_rewrite.so模块;2、将AllowOverride None中的None改为All;3、修改Apache配置文件.htaccess为“RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]”保存即可。

thinkphp5获取请求网址的方法:1、使用“\think\Request”类的“$request = Request::instance();”方法获取当前的url信息;2、通过自带的助手函数“$request->url()”获取包含域名的完整URL地址。

去除thinkphp5标题栏icon的方法:1、找到thinkphp5框架public下的favicon.ico文件;2、删除该文件或者选择另一张图片命名改为favicon.ico,并替换原favicon.ico文件即可。

thinkphp5 post得不到值是因为TP5是通过strpos函数在Header的content-type值中查找app/json字符串的,其解决办法就是设置Header的content-type值为app/json即可。

thinkphp5提示控制器不存在的解决办法:1、检查对应的控制器里面的命名空间是否写对,修改为正确的命名空间;2、打开相应的tp文件,修改类名即可。

ThinkPHP5查询昨天数据的方法:1、打开ThinkPHP5相关文件;2、通过表达式“db('table')->whereTime('c_time', 'yesterday')->select();”查询昨天的数据即可。

thinkphp5设置报错提示的方法:1、进入项目根目录下的public文件夹,打开index.php入口文件;2、查看调试模式开关的注释;3、将“APP_DEBUG”常量的值调整为true即可展示错误信息提示。
