We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10190
    • 187 Posts
    Hi,

    I'm currently coding snippets for modx revo (what a great piece of software, btw! smiley ).
    I would like to store user dependent data, so it's available as long as he's logged in (in his session?) and again if he loggs in again.

    How can that be achieved?

    BTW, as I'm pretty new to snippet coding in modx, I greatful for every hint to basic information regarding that topic - I find it rather difficult to get the tricks only be reading the api. I guess there are excellent tutorials and such available to dig deeper into it - any help is greatly appreciated!

    Cheers
    Frisco
      • 1343 ☆ A M B ☆
      • 2,213 Posts
      Hello Frisco,

      You should be able to accomplish that using the login extra: http://rtfm.modx.com/display/ADDON/Login

        Patrick | Server Wrangler
        About Me: Website | Tweets |  MODX Hosting
        • 10190
        • 187 Posts
        Hi AMDbuilder,

        if I got you right, you're talking about Custom Fields: http://rtfm.modx.com/display/ADDON/Login.Using+Custom+Fields

        If so, that would be great, as I'm already using the login extra.

        But I'm not sure if that suits my needs - I have to store some midsized multidimensional arrays for each user, which won't be displayed directly but should be used from my snippets. Could this be done with form fields in login from my own snippets?

        If I got it right, Revolution's User Profile has an "extended" field, where login stores the data. This field(s) should also be accessible via the manager.

        I guess another way would be to access these extended fields via modx api from my snippets directly. I would than use login (i.e. profile) to restore the data at user's login, but add/modify the data on my own.

        Do I have to dig into profile's source, or could you give me a hint how to deal with the extended field directly (or point me somewhere)?

        I try a brief description of what I like to do:

        First user login:

        • MySnippet generates some data for html output, this is shown
        • The generated data should be stored in user's extended fields

        Next user login:
        [li]MySnippet looks for user's extended fields, finds the stored data, and can display it directly - no initial generation necessary[/li]
        [li]Alternative: Login fetches the data from the user's ext. fields, MySnippet can work with it (how?)[/li]

        I hope this is comprehensible. Maybe I think too complicated, 'cause I'm new to snippet coding?

        Cheers
        Frisco
          • 22427
          • 793 Posts
          snippet coding .... basic information
          Have a look here:
          http://bobsguides.com/modx-snippets.html

          http://bobsguides.com/modx-snippet-faq.html
            • 10190
            • 187 Posts
            Hi ottogal,
            thanks, I'll have a look at these!

            @amdbuilder:
            I found it in the docs: http://rtfm.modx.com/display/revolution20/Users -> Using extended fields

            That's exactly what I was looking for, so thank's a lot for pointing me to logins extended fields, that took me to the right direction!

            Already tested and working, and that easy - another reason to love modx! smiley

            Cheers
            Frisco
              • 1343 ☆ A M B ☆
              • 2,213 Posts
              Glad to hear you were able to find what you needed, after all it's all there, you just need to find it smiley
                Patrick | Server Wrangler
                About Me: Website | Tweets |  MODX Hosting
                • 10190
                • 187 Posts
                That's exactly the point - what I'm now searching is how I can use the modx api to read a user field which is on the second tab, in german it's "Einstellungen", I assume the english modx would name it "settings" (first tab seems to be all the user's profile information, the extended is the fourth).

                I created a boolean user setting named "benchmark", which I found in the placeholders array, so it seems to get parsed - but I don't know how to read it via api.

                $profile = $modx->user->getOne('Profile');
                $fields = $profile->get('benchmark');


                This does not work, I tried different things like 'settings' for the get-call, but without success.

                Any clues about that?

                Cheers
                Frisco
                  • 10190
                  • 187 Posts
                  Found it in the api docs:

                  $arrSettings = $modx->user->getSettings();


                  gives an array with the settings. Great for WYPIWYG-implementations (What You Pay Is What You Get) ;-)

                  Cheers
                  Frisco
                    • 22303 MODX Staff
                    • 10,725 Posts
                    Note that settings are cached in the user session and may not be updated immediately for use when modifying the data. You could consider using the modRegistry (a simple message queue API available in MODX core) to store and retrieve user-specific data that needs to be maintained across sessions.