国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表

圖片精選

主站蜘蛛池模板: 杭锦旗| 开原市| 曲麻莱县| 鲁山县| 木兰县| 奎屯市| 南华县| 舒兰市| 治多县| 庆阳市| 芮城县| 绥滨县| 盖州市| 铜陵市| 安溪县| 馆陶县| 北川| 北海市| 鄱阳县| 杭锦旗| 阳谷县| 鲜城| 临朐县| 阿拉尔市| 那坡县| 江阴市| 麻江县| 上虞市| 成都市| 平遥县| 吴桥县| 赞皇县| 阳朔县| 崇仁县| 乳源| 恩施市| 康马县| 潼关县| 宣武区| 胶南市| 新化县|