Home > Backend Development > PHP Tutorial > ThinkPhp非法数据对象

ThinkPhp非法数据对象

不言
Release: 2023-02-28 16:16:01
Original
1516 people have browsed it

 $data = $_POST;  
     $data['user_id']    = 1;  
     $data['create_at']  = date("Y-m-d H:i:s");  
     $data['update_at']  = date("Y-m-d H:i:s");  
     $data['is_enable']  = 1;  
     $data['is_visible'] = 1;  
     $categoryModel  = new \Admin\Model\CategoryModel();  
     $footPosition   = $categoryModel->getFootPosition();  
     $data['position']   = intval($footPosition) + 1;  
  
  
 // var_dump($data);  
  $categoryModel->add($data);
Copy after login

我开始以为是position类型不对,可是不论转为string还是int,还是一样报非法数据对象错误。$data['position'] = intval($footPosition) + 1;这个注释掉插入数据就没问题了。求助啊.

var_dump后的结果如下,看不出什么问题啊。

array(7) { ["category_name"]=> string(12) "风言风语" ["user_id"]=> int(1) ["create_at"]=> string(19) "2015-04-
05 15:39:41" ["update_at"]=> string(19) "2015-04
-05 15:39:41" ["is_enable"]=> int(1) ["is_visible"]=> int(1) ["position"]=> int(2) }
Copy after login

数据库栏位position,已确定不包含空格,及栏位名称是一致的。

回复讨论(解决方案)

$footPosition = $categoryModel->getFootPosition();
后,打印出 $footPosition 看看是些什么

另外,出错时应给出原始的错误信息

问题已解决。进了ThinkPhp\Model,_facade函数,

   foreach ($data as $key=>$val){  
              file_put_contents("xiaobin.txt", $key."\n", FILE_APPEND) ;  
              file_put_contents("xiaobin.txt", $fields, FILE_APPEND);  
                 if(!in_array($key,$fields,true)){  
                     if(APP_DEBUG){  
                         E(L('_DATA_TYPE_INVALID_').':['.$key.'=>'.$val.']');  
                     }                      
                     unset($data[$key]);  
                 }elseif(is_scalar($val)) {  
                     // 字段类型检查 和 强制转换  
                     $this->_parseType($data,$key);  
                 }  
             }
Copy after login

发现field数组结果如下:category_iduser_idcategory_nameblog_numcreate_atupdate_atis_enableis_visiblepre_positionnext_positioncategory_idArray,这些都是数据库列名,其中pre_position,next_position是开始建表时的栏位,后来我删了这两列,添了position这一列。缓存已禁用,所以清除缓存也没用。  
最后发现这数据保存在Runtime/Data/_fields里,删了就好了。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template