<?php define('MODX_BASE_PATH', ''); define('MODX_BASE_URL', '/'); require_once MODX_BASE_PATH.'config.core.php'; require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php'; require_once MODX_CORE_PATH.'model/modx/modx.class.php'; $modx = new modX(); $modx->initialize('web'); $doc = $modx->getObject('modResource',array( 'id' => 1 )); $id = $modx->resource->get('id'); ?>
And why do you need to do it outside of MODx?I test a snippet under phpStorm. First, I have tried to test a document (as url) with the snippet call iincluded on the page (and then an active resource) but for some reasons (wrong configuration, may be), It don’t work.
The snippet output some resources (as rendered/ parsed output), but unfortunately Wayfinder (but probably some other addons) initialize by default the current resource as $modx->resource->get(’id’). So I get an error "Call to a member function get() on a non-object" error message.
Can you explain what you’re trying to do? Are you trying to create a resource, display an existing resource’s content, or what?
$modx->initialize('web'); if ($modx->getRequest()) { $request = new modRequest($modx); $request->getResource('id',1); }
return include "path/to/snippet/file";