$neededContext = $modx->resource->get('context_key');
Fatal error: Call to a member function get() on a non-object in [...]/core/cache/includes/elements/modplugin/1.include.cache.php on line 20
I get the context key like this:$neededContext = $modx->resource->get('context_key');
$neededContext = $modx->context->get('context_key');Thank you, but, as I understand, it will return currently used context, either ’mgr’ or ’web’ disregarding of the actual resource ’native’ context. Yes, I may search each context if a resource is there, but that’s slow...
I get the context key like this:
$neededContext = $modx->context->get('context_key');
Thank you! It now works. Well partially...
Looks as though your trying to access the resource object before its been determined and set, i.e. your to ’high’ in the plugin hierarchy to use it, try ’OnLoadWebDocument’ instead.
Or more generally, how do I efficiently load a resource from any context by its FURL? Thanks.
$name = 'modResource';
$criteria = array(
'published' => 1,
'alias' => 'your-alias-furl'
);
$document = $modx->getObject($name,$criteria);
$key = $document->get('context_key');
return ($key);
Thank you for the code and links! I’ll definitly make use of that.
Quote from: yurkobb at Jun 19, 2011, 04:10 AM
Or more generally, how do I efficiently load a resource from any context by its FURL? Thanks.
Ok, just going to guess here -
$name = 'modResource'; $criteria = array( 'published' => 1, 'alias' => 'your-alias-furl' ); $document = $modx->getObject($name,$criteria); $key = $document->get('context_key'); return ($key);
Thats one way to find out by furl which context that resource is in. But, it’s pretty hard working out what you’re trying to do - this is the wiki page on contexts - http://rtfm.modx.com/display/revolution20/Contexts & Bobs Quite Excellent Guide - http://bobsguides.com/revolution-objects.html
One thing - how are you displaying a resource from a different context at the moment - and are you doing any context switching?