Closed Jimmi08 closed 3 years ago
@Jimmi08 'data'=>'json'
converts a posted ARRAY to the json format. Your method may need to convert the json back to an array.
If you want to control the conversion yourself, then just use 'data'=>'str'
.
I don't know why you're getting PHP serialized data.
That data are already there, the table is shared with other CMS, so they have to stay untouched.
I used'data'=>'str'
... so only PHP serialize and unserialize should be used then? Not e107 way?
Thanks
Yeah, don't use the e107 serialize/unserialize, just the PHP ones. Using 'str' is the correct way in your case.
Thanks
@CaMer0n
back to this, only e107 way.
Could you look at hero plugin?
field:
'type' => 'method', 'data' => 'json',
Why are you doing this in method:
$value = e107::unserialize($curVal);
when data are already unserialized? $curVal is already an array?
@Jimmi08 The automatic unserialize was only recently added. (at your request, if I remember well) so some places still contain old manual calls to e107::unserialize(). The data should not be affected by this.
Sorry, again.
I use method +json without any troubles, everything works, unserialize is needed only in Admin UI form. Data type json is used. Working example:
'block_variables' => array('title' => LAN_OPTIONS, 'type' => 'method', 'data' => 'json', 'width' => 'auto', 'help' => '', 'readParms' => array(), 'writeParms' => array(), 'class' => 'left', 'thclass' => 'left', 'filter' => false, 'batch' => false, ),
Perfect.But now I have this type of data:
'a:1:{s:3:"num";s:1:"1";}'
It is a string and it has to left this way.So I changed type to 'str' :
'block_variables' => array('title' => LAN_OPTIONS, 'type' => 'method', 'data' => 'str', 'width' => 'auto', 'help' => '', 'readParms' => array(), 'writeParms' => array(), 'class' => 'left', 'thclass' => 'left', 'filter' => false, 'batch' => false, ),
e107::unserialize() works correctly first time (data are displayed in edit form)
Is it correct that I need to serialize data myself (only json does this itself) in before update/create methods?
Is correct that I can't use e107::serialize() because it saves array to string? - string array is there.
I tried to use native serialize()![image](https://user-images.githubusercontent.com/5429548/113692855-47fb1a00-96ce-11eb-8bb2-b24482fb6486.png)
$new_data['block_variables'] = serialize($new_data['block_variables']);
but it messed up quotes:and then e107::unserialize() doesn't work either.
What is wrong?
Thanks