ThinkPHP5 使用create 获取表单所有字段

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);
 
posted @ 2017-07-18 09:16  freedom/cn  阅读(4328)  评论(0编辑  收藏  举报