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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM