We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10525
    • 247 Posts
    I am looking for Revo 2.2.x API documentation for creating new users, setting profile info, changing passwords etc.

    I see some useful-looking info from Bob Ray here https://forums.modx.com/thread/31469/creating-a-new-web-user-with-the-api, and some here https://forums.modx.com/thread/74073/newobject-moduser--ok-but-how-add-user-attributes-fileds, but I would like to find the full set of available getter and setter functions for users/profiles/groups so I can quickly see what I can do via the API and what I need to write myself.

    Does this exist anywhere?

    I tried googling "$modx->newObject('modUser'" and there is nothing at all in an rtfm.modx.com page...

    To be honest, it almost looks quicker doing the whole thing manually via MySQL queries than searching for documentation, but I'm trying to do things the modx way, at least for creating a user and password correctly.
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      Below a bunch of links and quick code samples to get you started.. a lot of things in MODX work the exact same way, which is why you wont find much modUser-specific instructions.

      Generic usage that applies to all objects (xPDOObject) in MODX
      $user = $modx->newObject('modUser');
      $user->set('field','value');
      $user->save();


      http://rtfm.modx.com/xpdo/2.x/getting-started/using-your-xpdo-model/setting-object-fields
      http://rtfm.modx.com/xpdo/2.x/getting-started/using-your-xpdo-model/retrieving-objects
      http://rtfm.modx.com/xpdo/2.x/getting-started/using-your-xpdo-model/working-with-related-objects

      modUser specific

      source: https://github.com/modxcms/revolution/blob/develop/core/model/modx/moduser.class.php
      API docs: http://api.modx.com/revolution/2.2/db_core_model_modx_moduser.class.html#%5CmodUser (not a big fan of these API docs, prefer the source myself)

      $user = $modx->getObject('modUser', 1);
      $user->changePassword('newPass123456789', 'oldpassword');
      // or $user->changePassword('newPass123456789', '', true);
      
      $user->Profile->set('fullname', 'Rick Astley');
      $user->Profile->save();
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 10525
        • 247 Posts
        Thanks for that Mark.

        I was afraid of this. Looks like a sizeable learning curve to do things the new way.

        I see there are a few methods listed in the rtfm pages (eg modUser::changePassword()) (is this all of the non-generic methods?), while the rest of objects are handled via the newObject() and set() methods.

        Is there a quick reference to these objects available for getting/setting, and related objects? To be honest the detailed descriptions of classes and the api.modx.com docs are next to useless for reference as they are simply too big and complex. (I reminisce sadly for my beloved java docs of 12 years ago..).

        My feeling is that the data model is easier to reference just by looking in phpMyAdmin. Would this be the case?
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Why not use the Login extra? It comes with a bunch of snippets for handling users and their profiles.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 3749
            • 24,544 Posts
            The password field requires special handling. Pretty much everything else you just use this:

            $object->set('fieldName', $value);


            There's a handy reference to the object names, table names, and available fields here:

            http://bobsguides.com/modx-object-quick-reference.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
              • 10525
              • 247 Posts
              Susan, yes I use the Login snippet, but in this case I am adding extra fields in a custom table and these have to be added in to the create/update forms. I also make changes as I progress with development (and discuss with end-users), adding more fields where necessary.

              The problem I am finding with many extras is that, while they are very good for their own specialist functionality, they each also come with their own quirks, bugs, documentation quality, style and location. This leads to a whole load of time spent researching ways of doing the same stuff. Coding with PHP & MySQL avoids a lot of that because documentation for each is standardised and in the one place. So often it is easier just to code from scratch as opposed to spending time researching how to mod a snippet.

              I find it a bit surprising that so much effort is put into forcing developers to separate html from PHP code, while just anybody can dump an extra into a Package repository. There is a huge gulf in quality control here: many extras do not even have proper descriptions; there is no indication as to how well they function. The only rough guide is version number and number of downloads. I would love to see some kind of standardisation enforced upon extras authors too - in description, documentation and stated v proven level of functionality. Maybe some sort of sandbox area for new extras, combined with an easily-visible scoring system for users to score and comment. Extras should be demoted if they fail a target score level. This would allow developers to discriminate in how they elect to allocate their time on extras - choosing high-ranked ones for jobs that need done yesterday, and low-ranked ones only when you know you have time and willpower to test and provide feedback.

              As for the existing API, this seems to have all shifted away from good old-fashioned function names to a very generic and data-model-oriented system which is starting to resemble SQL. Handy reference lists are now huge pages of fairly technical information. As you say in your page linked above Bob, the listed MODX Revolution objects are "generated from the MODX schema file" (in other words the database). It's a huge list! Is all the info necessary, or could it be made more compact and informative? We need a data dictionary now. (btw that page would be great if it had a link to another page that told you what to actually do with all the stuff that is referenced, and what they mean. The inclusion of lines such as "-- use getMany('CreatedResources') -- returns an array of modResource objects" is good, but it would be great if we could just have a getCreatedResources() function?). While this has created a very flexible API for certain types of developers, it is also less intuitive without effectively having to scan the entire database schema. I feel that this has left a huge gap that the old Evo API used to fill (and which Java and PHP still do): intuitively-named functions which relate to obvious entities in MODx; getters and setters that do what they say on the tin. Is it not possible to have (at least a key set of) these alongside the more flexible (but long-winded) getOne() and getMany() etc functions?

              Maybe I'm just being blinkered and haven't read enough, maybe I just don't realise how much I have to relearn, but much as I love the idea of MODx, I just seem to have been a bit lost with it since having to move to Revo (due to server PHP upgrades). Maybe the system itself is brilliant, but it's the lack of coherent documentation (I keep going on about that I know). I don't intend to condemn anything, just to illustrate the experience of a modx user who doesn't build too may sites but also has to do a wide range of custom business-specific snippet development (ie not the same stuff over and over).

              Any comments to illuminate modx/educate me are welcome smiley


              ps, one final question: I keep finding links to the "More on the Anonymous User Group" page, but I cannot find any trace of a lesser page on Anonymous User Groups. Can anyone tell me?
                • 3749
                • 24,544 Posts
                getCreatedResources() would be what we call a "convenience function" and you're welcome to submit a feature request for it. A number of them have been created already (e.g., getChildIds(), getTVValue()).

                When I first started using Revo, I wanted a lot of convenience functions too. Over time, though, as I got used to xPDO, I came to appreciate how xPDO allowed me to do almost anything using the same small set of generic methods. I can now write code for at least 95% of the things I need off the top of my head without any reference to the API docs -- a state of affairs that I never got within miles of with Evolution.

                YMMV. wink

                  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
                  • 10525
                  • 247 Posts
                  As regards my gripes with addons (above), I just came across this thread,which at least acknowledges a lot of stuff that needs fixed. Good to know this is on the table, or at least being spoken about by the core dev team.

                  https://forums.modx.com/thread/?thread=82654&page=1

                    • 3749
                    • 24,544 Posts
                    I think the core dev. team is well aware of these issues. I'm hoping that some of that will be addressed in MODX 2.3 and even more in 3.0, which will involve fixes and features that can't be implemented now due to incompatibility with legacy code.
                      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