We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16858
    • 58 Posts
    I have been using the below method for several months now and it has worked really well for me and would like to see it built-in to ModX.

    Everyone has different fields they want to include for User profile information and there is no way you can include fields that meets everyone needs. What I have been doing is I made the comment field of web_user_attributes longtext and then use the following code at the top of all my snippets:

    global $modx;
    $_userID = $modx->getLoginUserID();
    if ($_userID) {
        $User = $modx->getWebUserInfo($_userID);
        if ($User[comment]) {
            preg_match('|<security_level>(.*)</security_level>|', $User[comment], $matches);
            $User[security_level] = $matches[1];
        }
    }


    Using the above code, all I have to do is include <security_level>7</security_level> in the comment section and voila, now I have a $User variable called $User[security_level]. With this method, I can include only the fields that are relative to each user. I normally include one tag on each line followed by a return.

    So ... it would be nice to add a longtext box to the User profile page entitled XML Variables or something similar which ModX would automatically read and apply all tags in that users profile to the $User variable (or some other variable).

    Additionally, using this method, no mass changes to the web_user_attributes table would need to be made, which would take away the concern of updates and the need to alter a table structure each time an update so required.

    I hope this makes sense, because the concept has really worked well for me with ModX.
      • 22303 MODX Staff
      • 10,725 Posts
      Why store it as XML, which just requires that you use regular expressions or an XML parser to read the data? I believe that is just extra overhead that can be avoided when serving dynamic pages. You could just as easily store serialized PHP in a db field and use it much more efficiently, and take up less space.

      Also, why not just use web_user_settings to store and retrieve this data? It already has the ability to store custom key-value pairs and is a text field, which supplies plenty of space to store a large amount of data on just about any modern server.
        • 16858
        • 58 Posts
        Sounds good. I was not aware of web_user_settings ... how do I access that from the web interface?