国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > ThinkPHP > 正文

thinkphp5的get和post數(shù)據(jù)封裝的方法介紹(代碼)

2024-09-09 15:20:29
字體:
供稿:網(wǎng)友

本篇文章給大家?guī)淼膬?nèi)容是關(guān)于thinkphp5的get和post數(shù)據(jù)封裝的方法介紹(代碼),有一定的參考價(jià)值,有需要的朋友可以參考一下,希望對你有所幫助。

thinkphp5的get和post數(shù)據(jù)封裝

一、view(html頁面獲取數(shù)據(jù))

二、控制器

一、view(html頁面獲取數(shù)據(jù))

  1. <form action="index"
  2.  
  3.     <input type="text" name="status" value="{$where.nireid}" placeholder="狀態(tài)" > 
  4.  
  5.     <input type="text" name="atype" value="{$where.atype}" placeholder="類型" > 
  6.  
  7.     <input type="text" name="nireid" value="{$where.nireid}" placeholder="昵稱" > 
  8.  
  9.     <button type="submit" > 搜索</button> 
  10.  
  11. </form> 

二、控制器

1、正常情況下我們是這樣操作的

  1. public function index(){  
  2.  
  3.      $where['status'] =input('get.status'); 
  4.  
  5.      $where['atype'] =input('get.atype');  
  6.  
  7.      $where['nireid'] =input('get.nireid'); 
  8.  
  9.      $this->assign('where',$where); 
  10.  
  11.      $this->assign(UserExtractModel::systemPage($where)); 
  12.  
  13.      return $this->fetch(); 
  14.  

2、其實(shí)我們可以這樣做

  1. public function index(){  
  2.  
  3.      $where = self::getMore([ 
  4.  
  5.           ['status',''], 
  6.  
  7.           ['atype',''], 
  8.  
  9.           ['nireid',''], 
  10.  
  11.      ],$this->request); 
  12.  
  13.      $this->assign('where',$where); 
  14.  
  15.      $this->assign(UserExtractModel::systemPage($where)); 
  16.  
  17.      return $this->fetch(); 
  18.  
  19.   
  20. public function getMore($params,Request $request=null,$suffix = false){ 
  21.  
  22.      if($request === null) $request = Request::instance(); 
  23.  
  24.      $p = []; 
  25.  
  26.      $i = 0; 
  27.  
  28.      foreach ($params as $param){ 
  29.  
  30.           if(!is_array($param)) { 
  31.  
  32.                $p[$suffix == true ? $i++ : $param] = $request->get($param); 
  33.  
  34.           }else
  35.  
  36.                if(!isset($param[1])) $param[1] = null; 
  37.  
  38.                if(!isset($param[2])) $param[2] = ''
  39.  
  40.                $name = is_array($param[1]) ? $param[0].'/a' : $param[0]; 
  41.  
  42.                $p[$suffix == true ? $i++ : (isset($param[3]) ? $param[3] : $param[0])] = $request->get($name,$param[1],$param[2]); 
  43.  
  44.           } 
  45.  
  46.      } 
  47.  
  48.      return $p
  49.  

(不要忘記use think/Request;)

(post同理)

以上就是thinkphp5的get和post數(shù)據(jù)封裝的方法介紹(代碼)的詳細(xì)內(nèi)容。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 临沭县| 河北区| 黑山县| 满城县| 巫溪县| 彰化市| 宁城县| 隆安县| 宁蒗| 三明市| 大方县| 同心县| 分宜县| 芜湖市| 肥乡县| 清苑县| 桃园县| 宜君县| 金溪县| 迁安市| 勃利县| 中西区| 白城市| 六盘水市| 南康市| 桐城市| 海门市| 漳州市| 莱州市| 乐平市| 岚皋县| 庆城县| 亚东县| 济源市| 江源县| 岳阳市| 玉龙| 建水县| 且末县| 葫芦岛市| 蓝山县|