Announcement

Collapse
No announcement yet.

Serialize structure to custom field?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Serialize structure to custom field?

    hi, I have this code which is attempting to store a structure I have built up.

    <mvt:item name="customfields" param="Write_Category_Code( 'homepage-highlights-large', 'homereviews', miva_array_serialize(l.settings:homereviews:review s) )" />

    Then on another page, I'm attempting to read that field back in and use it, but I don't get anything:

    <mvt:item name="customfields" param="Read_Category_Code( 'homepage-highlights-large', 'homereviews', miva_array_deserialize( l.settings:homereviews:reviews) )" />

    when I look at the field in the database, I'm not able to edit the value from the list view UI like other records (see attached, last record).

    When I view the record, data gets assigned to value_long, instead of the default "value", and I can see the structure there. The data that's getting stored in this record is somewhat large, but doesn't come close to exceeding mySQLs limit for mediumText, which is what value_long is set to. Am I doing something wrong? Can you not store arrays in custom fields, in this case a category field?Screen Shot 2018-11-19 at 11.50.57 AM.png

    #2
    I'm not sure you can deserialize it in the Read_Category_Code function. Try that out into a second line after you read it in.
    Brennan Heyde
    VP Product
    Miva, Inc.
    [email protected]
    https://www.miva.com

    Comment


      #3
      The Write element looks OK to me. There's a space in the variable name "l.settings:homereviews:review s," but the forum seems to do that to posted text sometimes.

      For the Read Element, you need another step. First you read the custom field into a variable, and then you deserialize the variable into another variable, or back into itself.

      You should be able to serialize any kind of variable, including arrays and nested structures such as arrays of objects. The store will use the value_long column any time the data is longer than 254 characters, the maximum for VARCHAR columns in SQL.
      Kent Multer
      Magic Metal Productions
      http://TheMagicM.com
      * Web developer/designer
      * E-commerce and Miva
      * Author, The Official Miva Web Scripting Book -- available on-line:
      http://www.amazon.com/exec/obidos/IS...icmetalproducA

      Comment


        #4
        Thanks Guys, works like a charm after I deserialized the variable after!

        Comment

        Working...
        X