We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10449
    • 956 Posts
    I’m using a Ditto call with the API runSnippet function. Runs fine and as expected when in a snippet, i.e. showing in the frontend.

    However, the exact same code just throws up very strange errors, when run as a module.

    
    $container = 119;
    $p['parents'] = $container;
    $p['tpl'] = 'idTPL'; // [+id+],
    $p['total'] = 999;
    $p['display'] = 999;
    $p['showPublishedOnly'] = 0;
    $p['showInMenuOnly'] = 0;
    $p['seeThruUnpub'] = 1;
    $p['filter'] = 'published,0'; // apparently needed for Ditto v. 2.1 : http://modxcms.com/forums/index.php/topic,22398.0.html
    $p['debug'] = 1;
    $p['sortDir'] = 'ASC';
    $p['sortBy'] = 'pagetitle';
    
    $snippet = $modx->runSnippet('Ditto', $p);
    
    // cut off last comma:
    $len = strlen($snippet);
    $wholeTeam = substr($snippet, 0, $len-1); // list with all the team-IDs, comma-separated.
    $wholeTeamArray = explode(",", $wholeTeam); // string -> array
    
    echo '<pre>';
    print_r($wholeTeamArray);
    echo '</pre>';
    
    



    Again, this runs fine in a snippet. In a module, I get the following error:

    MODx Parse Error »
    MODx encountered the following error while attempting to parse the requested resource:
    « `` is not numeric and may not be passed to makeUrl() »

    Parser timing
    MySQL: 0.0018 s (3 Requests)
    PHP: 1220563559.0300 s
    Total: 1220563559.0317 s

    This is driving me insane. I even tried to explicitly include:

    include_once( '/var/www/virtual/oh-hello.com/htdocs/modxapi.php' );
    $modx = new MODxAPI();
    $modx->connect();
    $modx->getSettings();
    

    that did nothing whatsoever though...


    Ditto 2.1.0
    MODx 0.9.6 rev 2767
    mySQL 5.0.32
    PHP 5.2.0-8+etch11
      • 3749
      • 24,544 Posts
      Just a wild guess, but have you tried using single quotes in the explode statement?
        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
        • 10449
        • 956 Posts
        Doesn’t matter. Same thing.

        It seems to choke on the Ditto call.

        I also tried using published docs and removed the filter etc. Same thing.

        And what’s with the very strange, insanely high parsing times displayed? o_O
          • 7231
          • 4,205 Posts
          Try outputting the Ditto call directly, before the array processing, to see if it is the Ditto call or not.

          I thought that filter needed 3 parameters (field,criteria,method). But if you removed that and it still did not work, then this is not the problem.
            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don&#39;t know what it is.
            Do you, Mr. Jones? - [bob dylan]
            • 10449
            • 956 Posts
            Thanks, but it’s definitely Ditto. I made a test that ends with:
            $snippet = $modx->runSnippet(’Ditto’, $p);
            Still no go.

            re: Number of filter parameters: If it works in the frontend with 2 parameters, why should it fail when I run it in a module?
            Besides, Mark uses only two in this thread: http://modxcms.com/forums/index.php/topic,22398.msg143984.html#msg143984
            Who would know better than him? smiley

            Somewhere along the line, $modx->makeUrl() is used. That’s not in my code, it’s got to come from somewhere else.
            If I interpret this right, then modx doesn’t receive a parameter for makeUrl. But why that id would get lost, is beyond me.
            `` is not numeric and may not be passed to makeUrl()



            Anyway, I decided to not lose any more time (and hair) with this, so I moved everything to the frontend, where I know it will work as advertised :]