TP5沒有 TP3的那個create創建表單字段,如果字段太多,寫起來是非常麻煩
只需要在 框架里面 think/db/Query.php 里面加上函數
public function create($data=null){ if($data==null){ $data=input("post."); } $new_data=[]; $field=$this->getTableFields($this->options); foreach($field as $f){ foreach($data as $key => $value){ if($f==$key){ $new_data[$f]=$value; } } } return $new_data; }
使用方法
$model = DB::name("Diabetes");
$list = $model->create();
$model->insert($list);
