I get a fatal error with the following script running outside of MODx :
<?php
define('MODX_BASE_PATH', 'E:/www/modx204/');
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');
// get not deleted, published and searchable documents
$documents = $modx->getCollection('modResource',array(
'deleted' => 0,
'published' => 1,
'searchable' => 1,
'context_key' => 'web'
));
if (!empty($documents)) {
foreach ($documents as $document) {
$content = $document->get('content');
if (!empty($content)) {
// get the max iterations tags are processed before processing is terminated
$maxIterations= (integer) $modx->getOption('parser_max_iterations', null, 10);
// parse all cacheable tags first
$modx->getParser()->processElementTags('', $content, false, false, '[[', ']]', array(), $maxIterations);
// parse all non-cacheable and remove unprocessed tags
$modx->getParser()->processElementTags('', $content, true, true, '[[', ']]', array(), $maxIterations);
}
}
}
?>
Fatal error: Call to a member function get() on a non-object in E:\www\modx204\core\cache\elements\modsnippet\6.include.cache.php on line 49
The pb happens with a document where the content contains [[!SimpleSearchForm]] [[!SimpleSearch]]
the error happens with this part of code : $modx->resource->get(’id’)
$placeholders = array(
'method' => $modx->getOption('method',$scriptProperties,'get'),
'landing' => $modx->getOption('landing',$scriptProperties,$modx->resource->get('id')),
'searchValue' => $searchValue,
'searchIndex' => $searchIndex,
);
I have no problems inside MODx with this document. But outside with above script I got this error.
How could I set up the parsing outside of MOdx ?
Is it correct to use:
// get the max iterations tags are processed before processing is terminated
$maxIterations= (integer) $modx->getOption('parser_max_iterations', null, 10);
// parse all cacheable tags first
$modx->getParser()->processElementTags('', $content, false, false, '[[', ']]', array(), $maxIterations);
// parse all non-cacheable and remove unprocessed tags
$modx->getParser()->processElementTags('', $content, true, true, '[[', ']]', array(), $maxIterations); in this case to parse the content of a document ? What is missing or wrong ?