Illegal ThinkPhp data object

Source: Internet
Author: User
ThinkPhp illegal data object $ 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 _ visable'] = 1;
$ CategoryModel = new \ Admin \ Model \ CategoryModel ();
$ FootPosition = $ categoryModel-> getFootPosition ();
$ Data ['position'] = intval ($ footPosition) + 1;


// Var_dump ($ data );
$ CategoryModel-> add ($ data );
I started to think that the position type is incorrect. However, whether it is converted to string or int, an invalid data object error is returned. $ Data ['position'] = intval ($ footPosition) + 1; this annotation removes the need to insert data. For help.

The results after var_dump are as follows. No problem is found.
Array (7) {["category_name"] => string (12) "文" ["user_id"] => int (1) ["create_at"] => string (19) "15:39:41" ["update_at"] => string (19) "15:39:41" ["is_enable"] => int (1) ["is_visible"] => int (1) ["position"] => int (2 )}

Position of the database column. it is determined that it does not contain spaces and the column name is consistent.


Reply to discussion (solution)

$ FootPosition = $ categoryModel-> getFootPosition ();
And print $ footPosition to see what it is.

In addition, the original error information should be provided when an error occurs.

The problem has been solved. The ThinkPhp \ Model, _ facade function, 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 )){
// Field type check and forced conversion
$ This-> _ parseType ($ data, $ key );
}
}
The result of the field array is as follows: Values, which are the database column names. pre_position and next_position are the column spaces when the table is created. I deleted these two columns, added the position column. The cache is disabled, so it is useless to clear the cache.
The Data is saved in Runtime/Data/_ fields and deleted.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.