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

    $did = $modx-resource-get('id');


    it works in snippets!
    But in plugins it only works this way:

    $did = $resource-get('id');


    Why is this?

    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/
      • 40706
      • 128 Posts
      I think because of the manager uses something like resources on its own for the manager pages.

      Which variables are available on Plugins should be checked for every Event in the long List of System Events.
      http://rtfm.modx.com/display/revolution20/System+Events
        • 40045
        • 534 Posts
        First of all, I'm not sure if I'm getting what you are saying, but I just had a look in a plugin I wrote a few days ago, and there I have stuff like this:

        // event OnWebPageComplete
        $modx->getOption('base_path') . 'some/path/' . $modx->resource->get('id') . '/';


        obviously there is just that

        $modx->resource->get('id')


        like it's also used in snippets, so I don't see the problem you have there, maybe it's depending on the event? Not sure about that. When you have this problem, which event are we talking about?

        What I recently noticed is that the available variables are not always correctly listed in the rtfm. For example
        $modx->resource
        is also available in OnWebPageComplete but the rtfm says under available variables "none", so first check what's written in the RTFM and then if you need it in an event where is written "none" try it anyway =P. [ed. note: exside last edited this post 11 years, 5 months ago.]
        • One is part of the $modx object, the other is a resource object provided by the event function.
            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
          • discuss.answer
            • 3749
            • 24,544 Posts
            It depends on the event. For many front-end events, $modx->resource and $modx->user are set. For events that fire in the manager, though, they usually are not, so the code that invokes the event sends $user or $resource to the event.

            Here's an example:

            $this->modx->invokeEvent('OnDocFormSave', array(
               'mode' => modSystemEvent::MODE_NEW,
               'id' => $this->object->get('id'),
               'resource' => &$this->object,
               'reloadOnly' => $this->getProperty('reloadOnly',false),
            ));


            $modx->resource is not set at this point, so the code sends the $resource variable along for use in plugins that respond to OnDocFormSave.

              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
              • 40045
              • 534 Posts
              Perfect explanation @Bob! Thank you very much!
                • 10378
                • 375 Posts
                Thank you Bob (again),

                hope the MODx documentation gets updated soon as I'd like to find this kind of informations for myself.

                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/
                  • 10378
                  • 375 Posts
                  Thanks also to all others for your help!
                    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/
                    • 10378
                    • 375 Posts
                    Quote from: exside at Dec 05, 2012, 12:01 PM
                    First of all, I'm not sure if I'm getting what you are saying, but I just had a look in a plugin I wrote a few days ago, and there I have stuff like this:

                    // event OnWebPageComplete
                    $modx->getOption('base_path') . 'some/path/' . $modx->resource->get('id') . '/';


                    obviously there is just that

                    $modx->resource->get('id')


                    like it's also used in snippets, so I don't see the problem you have there, maybe it's depending on the event? Not sure about that. When you have this problem, which event are we talking about?

                    What I recently noticed is that the available variables are not always correctly listed in the rtfm. For example
                    $modx->resource
                    is also available in OnWebPageComplete but the rtfm says under available variables "none", so first check what's written in the RTFM and then if you need it in an event where is written "none" try it anyway =P.

                    Hi exside,

                    I'm using some backend/manager events like OnDocFormSave, OnDocPublished, ...
                    It turns out that in plugins you don't have always access to all MODx variables.

                    The event you used in your example above uses a frontend event.

                    Thanks for jumping in!
                    Martin [ed. note: gadgetto last edited this post 11 years, 5 months ago.]
                      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 think the RTFM info just lists the variables sent in the invokeEvent() call (as does my book), so if $modx->resource or $modx->user happen to be available (as they often are in the front end), they won't be listed.
                        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