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.