We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27330
    • 884 Posts
    Hi everyone,
    I have 4 different web apps co-exist with my modx site. I would like to access my modx menus from these apps so I don't need to edit 4 different files every time I make changes to a menu.

    I've tried adding this stanza in a template file of external app but nothing is displayed.

    <?php 
    // adding modx to search
    	require_once '/usr/local/www/mysite.com/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('getResources', array('parents' => '48', 'tpl'=>'latestPostsTpl'));
    	echo $html;
    ?>
    


    is there any guide or pointers how to do what I'm trying?
    TIA
      • 39404
      • 175 Posts
      stalemate resolution associate Reply #2, 13 years, 5 months ago
      Hi TIA,

      I'm no expert in these things, but as a few guesses on things to try:
      1) O/S Security: Check to see if the user running the script has access to those folder. To test this, try echoing MODX_CORE_PATH
      2) Site Security: if your web site has security running on it, latestPostsTpl might only be available to certain users. According to your script, you're running as an anonymous user

      Hope this helps,
      Tom
        • 4172
        • 5,888 Posts
        you may need to set the &context-property or/and a $modx->resource - object before calling getResources.

        Can't you put this snippet-call on a Resource with an empty-template and call its url?
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 38290
          • 712 Posts
          Definitely echo core path to make sure MODX is instantiated correctly. Likely do need to pass in context to getResources but if that still doesn't work I would suggest using a xPDO where query rather than getResources
            jpdevries
            • 3749
            • 24,544 Posts
            Sinbad, see if adding this helps:

            $modx->getRequest();
            $homeId = $modx->getOption('site_start');
            $homeResource = $modx->getObject('modResource', $homeId);
            
            if ($homeResource instanceof modResource) {
                $modx->resource = $homeResource;
            } else {
                echo "\nNo Resource\n";
            }
            $id = 1;  // some user's ID
            $user = $modx->getObject('modUser', $id);
            $modx->user = $user;
            
            
              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