We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38371
    • 42 Posts
    Hello to everyone,

    I have a situation were I want to parse the value of the column "input_properties". The corresponding tab in the Manager Page of TVs is entitled "Input Options".

    I understand the format in which they are stored. However, before I implement a custom method for their parsing I would like to know if there is an already created one.

    I would like to parse something like the following:
    a:3:{s:10:"allowBlank";s:4:"true";s:9:"maxLength";s:0:"";s:9:"minLength";s:0:"";}
    


    to an array of key-value pairs.

    So, my question is if there is a method that parses the "input_properties" of a TV into an array and what is that?

    Thank you very much.
      • 3749
      • 24,544 Posts
      I don't know of any simple way to do that. Whenever you ask MODX for the value of a TV, you get the one selected in the Manager (or the default, or inherited value if any).

      This is off the top of my head, but I think what you want is this:

      <?php
      $id = 12; // ID of the TV
      $tv = $modx->getObject('modTemplateVar', $id);

      $values = $tv->get('elements') // If the values you want are in the 'element' field in the DB
      // or
      $values = $tv->getProperties(); // If they're in the 'properties' field.

      In the first case, you'd need to parse the values yourself. In the second, they should already be converted to a PHP array for you.


      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 38371
        • 42 Posts
        Thank you very much for the reply BobRay and sorry for being late in replying.

        You were right.

        You just write:

        $properties = $tv->get('input_properties');


        and the $properties variable gets an array of key-value pairs of the following form:

        $properties['allowBlank'] = true;
        $properties['maxLength'] = 3;


        etc...

        Bottom line, no special parsing is needed.

        Thanks a lot for your answer.