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

    I'd like to get the context-key of a specific resource (or resource container) from within a Custom Manager Page. All I have is the ID of the resource/container document.

    The getContext method from the modx.class returns the actual context-key. Inside a CMP this will always return "mgr".

    Is there something like "getContextByResourceID"?
    Or how can this be done?

    --
    Greetings,
    Martin

    This question has been answered by BobRay. See the first response.

      Freelancer @bitego http://www.bitego.com
      ---
      GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
      More infos here: http://www.bitego.com/extras/goodnews/
    • discuss.answer
      • 3749
      • 24,544 Posts
      If you have the resource object, it would be:

      $resource->get('context_key');


      If all you have is the ID, you could do this:

      $res = $modx->getObject('modResource', $id);
      $ctx = $res->get('context_key');



      ------------------------------------------------------------------------------------------
      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
        • 10378
        • 375 Posts
        Hi Bob,

        as always fast and simple answer! Thank you again!

        Looking at your answer this is so easy. As a beginner (with MODx and PHP) it's hard to figure out how to do such things...

        Are there good programming tutorials regarding the MODx Revo API and xPDO (best would be step by stept tuts)?

        Looking at the core code might help if you are an advanced developer - but without knowing the basics it's hard to read the code. Its even hard to know where to look for!

        How did you pros come to such an advanced level?

        Greetings,
        Martin
          Freelancer @bitego http://www.bitego.com
          ---
          GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
          More infos here: http://www.bitego.com/extras/goodnews/
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Time. I've just begun to examine Revo a few months ago, and I'm finally beginning to understand the way it works.

          You can also examine the class reference and the API reference, although it takes a bit of studying to figure out the API reference material.

          http://rtfm.modx.com/display/revolution20/Class+Reference
          http://api.modx.com/revolution/2.2/

          Bob's guides and tutorials are invaluable! And his book is said to be great. I don't have that one, but I do have Shaun Wlkerson's book, and am quite pleased with it. Shaun also has some good articles and tutorials on his site. [ed. note: sottwell last edited this post 14 years ago.]
            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
            • 10378
            • 375 Posts
            Hi Susan,

            thanks for your hints! I already know the class reference and the api doc. What I miss in the docs are examples, use cases and more detailed descriptions.

            By the way - is it only me or causes the usage of the search input in the api documentation a complete browser freeze?

            Greetings,
            Martin
              Freelancer @bitego http://www.bitego.com
              ---
              GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
              More infos here: http://www.bitego.com/extras/goodnews/
              • 3749
              • 24,544 Posts
              I don't know. I always look in the MODX code rather than searching the API. My editor (PhpStorm) has a nice regular-expression, multi-file search function and will also jump to a method declaration anywhere in MODX if I right-click on a call.


              ------------------------------------------------------------------------------------------
              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
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                I bought myself a copy of that when they had it half-price, now I just need to get myself motivated to learn how to use it!
                  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
                  I got one then too. I think you'll like it. I made a complete MODX install into a PhpStorm project and put my own projects in the assets directory. Just do File -> New Project, and select the MODX root directory.


                  ------------------------------------------------------------------------------------------
                  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