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標題列icon的方法:1、找到thinkphp5框架public下的favicon.ico檔案;2、刪除該檔案或選擇另一張圖片命名改為favicon.ico,並取代原favicon.ico檔案即可。

thinkphp5取得請求網址的方法:1.使用「\think\Request」類別的「$request = Request::instance();」方法取得目前的url資訊;2、透過自帶的助手函數「$request-> url()」取得包含網域的完整URL位址。

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即可展示錯誤訊息提示。
