We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5811
    • 1,717 Posts
    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 ?
      • 3749
      • 24,544 Posts
      Have you tried:

      $modx->initialize('mgr');

      ??

        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
        • 5811
        • 1,717 Posts
        I get the same result with $modx->initialize(’mgr’); sad
          • 21257 MODX Staff
          • 730 Posts
          Does it help to set
          define('MODX_API_MODE', true);
          
            Mike Schell
            Lead Developer, MODX Cloud
            Email: [email protected]
            GitHub: https://github.com/netProphET/
            Twitter: @mkschell
            • 28215
            • 4,149 Posts
            Try adding this before calling the element parsing:

            $modx->resource =& $document;
              shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
              • 5811
              • 1,717 Posts
              No more results with define(’MODX_API_MODE’, true); sad
                • 5811
                • 1,717 Posts
                Ok, it runs with $modx->resource =& $document; laugh
                        if (!empty($content)) { 
                        
                            $modx->resource =& $document;
                            
                            // 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, true, false, '[[', ']]', array(), $maxIterations);
                
                            // parse all non-cacheable and remove unprocessed tags 
                            $modx->getParser()->processElementTags('', $content, true, true, '[[', ']]', array(), $maxIterations);    
                
                echo $content. '< br/>';     
                The content is now correctly parsed.

                Thanks!