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

ThinkPhp非法数据对象解决办法

WBOY
Release: 2016-06-13 12:17:26
Original
1480 people have browsed it

ThinkPhp非法数据对象
 $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);
我开始以为是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) } 

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

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

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

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