We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7674
    • 4 Posts
    Hello, colleagues.

    I try to run Wayfinder with modx->runSnippet from external file. But I get error: "Fatal error: Call to a member function get() on a non-object in /srv/www/relaxmenu.ru/public_html/core/components/wayfinder/wayfinder.class.php on line 40". Also I get error like this, when try to call getResources snippet;

    here is my code:

    <?php
    require_once(’ru/rialaunch/model/vo/SectionInfo.php’);
    require_once($_SERVER[’DOCUMENT_ROOT’].’config.core.php’);
    require_once(MODX_CORE_PATH.’model/modx/modx.class.php’);

    $modx = new modX();
    $modx->initialize(’web’);
    $modx->getService(’error’,’error.modError’);
    $html=$modx->runSnippet(’Wayfinder’,array(’startId’,’2’));
    echo $html;
    ?>

    What could be wrong?
      • 26903
      • 1,336 Posts
      Line 40 is doing this :-
      'id' => $this->modx->resource->get('id'),

      So you have no resource object in your modx object, this will be the case as you are instantiating the modx object from an external script and not processing a
      normal page request.

        Use MODx, or the cat gets it!
        • 18373 ☆ A M B ☆
        • 3,141 Posts
        Try using one resource as "controller" - putting either that external script there, or the actual snippet you are trying to invoke. So letting that resource return the actual content you need.

        That will then handle the request stuff and make sure there is a resource object.
          Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

          Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
          • 7674
          • 4 Posts
          thanks