We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40045
    • 534 Posts
    I'm currently playing around with the xFCP Plugin (which by the side is already very nice, but I want to make it nicer =D) but I'm nagging on some limitations I couldn't find a solution for after trying for a couple of hours.

    What I'm trying to do is not only related to this plugin, so I post this in the General Support forums:

    The main question is in the topic title and here's an example for it (read the comments in the code pls):

    $eventName = $modx->event->name;
    switch($eventName) {
    	case 'OnLoadWebDocument':
    		$dir = $modx->getOption('base_path') . 'core/cache/fpc/' . $modx->resource->get('id') . '/';
    		// some other stuff
    		break;
    	case 'OnWebPageComplete':
    		// here I really need that $dir variable again, but I cannot generate or reference it (I think at least) 
    		// because on this event I don't have a reference to $modx->resource
    		// so how can I pass this $dir variable to this event? Is this even possible?
    		break;
    }
    


    any idea, or am I just blind or plain stupid? =) (I admit that my php skills suck...so no problem with hearing it...anybody?)


    EDIT: OK, I'm half stupid^^... just tried what I've written above (try'n'error) and tried to reference $modx->resource in the OnWebPageComplete part of the plugin, and see, IT WORKED...but the docs http://rtfm.modx.com/display/revolution20/OnWebPageComplete just say "None" under Event Parameters while it says "None. The resource can be referenced via $modx->resource." in the docs for OnLoadWebDocument http://rtfm.modx.com/display/revolution20/OnLoadWebDocument ...

    so just for clarification: Is $modx->resource everywhere available (in every system event) or is this just a bug in the documentation and should be fixed by somebody who knows on which events $modx->resource is available? [ed. note: exside last edited this post 13 years, 10 months ago.]
      • 10487 MODX Staff
      • 1,535 Posts
      Try storing the value in the $modx->placeholders array by using $modx->setPlaceholder('myPlugin.dir', $dir) and retrieving it with $modx->getPlaceholder('myPlugin.dir').
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 40045
        • 534 Posts
        Wow, thanks for the fast answer Garry, nice idea with $modx->placeholders, can probably use that in another scenario (ie. when $modx->resource or sthing similar is really not available =P)! I edited my first post...already got the solution way easier than I thought =))...