e107inc / e107

e107 Bootstrap CMS (Content Management System) v2 with PHP, MySQL, HTML5, jQuery and Twitter Bootstrap. Issue Discussion Room: https://gitter.im/e107inc/e107
https://e107.org
GNU General Public License v3.0
321 stars 213 forks source link

question to e107 serialize/unserialize vs string #4481

Closed Jimmi08 closed 3 years ago

Jimmi08 commented 3 years ago

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() $new_data['block_variables'] = serialize($new_data['block_variables']); but it messed up quotes: image

and then e107::unserialize() doesn't work either.

What is wrong?

Thanks

CaMer0n commented 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.

Jimmi08 commented 3 years ago

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

CaMer0n commented 3 years ago

Yeah, don't use the e107 serialize/unserialize, just the PHP ones. Using 'str' is the correct way in your case.

Jimmi08 commented 3 years ago

Thanks

Jimmi08 commented 3 years ago

@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?

CaMer0n commented 3 years ago

@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.