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);
 

相关文章:

  • 2021-12-10
  • 2022-12-23
  • 2021-10-03
  • 2021-06-10
  • 2022-01-30
  • 2022-12-23
  • 2021-05-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-15
相关资源
相似解决方案