We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45374
    • 18 Posts
    I am attempting to follow the Doodles tutorial.

    My model seemed to get created correctly.

    My file paths are set up in system settings.

    My php file is set up as a Static Snippet.

    That Static Snippet is running from a Document in MODx... but $dood is not getting instantiated and I'm not sure how to figure out why that's not happening.

    $defaultDoodlesCorePath = $modx->getOption('core_path').'components/doodles/';
    print "<br>default core path: ";
    print $defaultDoodlesCorePath;
    $doodlesCorePath = $modx->getOption('doodles.core_path',null,$defaultDoodlesCorePath);
    print "<br>doodles core path: ";
    print $doodlesCorePath;
    print "<br>Script Properties: ";
    print_r($scriptProperties);
    print "<br>";
    $dood = $modx->getService('doodles','Doodles',$doodlesCorePath.'model/doodles/',$scriptProperties);
    print "<br>dood object:";
    var_dump($dood);
    
    if (!($dood instanceof Doodles)) return '';
    
    // The code does not reach this point.
    


    I broke the line down into three lines as he does in his tutorial discussing what it is doing.

    Here is what the output in the browser is:

    default core path: /var/www/html/modx-2.2.10-pl/core/components/doodles/
    doodles core path: /var/www/html/doodles/core/components/
    Script Properties: Array ( ) 
    
    dood object:
    null


    What can I check to figure out why this object is not coming back...?

    doodles.class.php is located here:

    /var/www/html/doodles/core/components/doodles/model/doodles/doodles.class.php

    The snippet.doodles.php file is located here:

    /var/www/html/doodles/core/components/doodles/elements/snippets/snippet.doodles.php

    [This is MODX Revolution 2.2.10-pl (traditional).]

    This question has been answered by BobRay. See the first response.

    [ed. note: coderjeff last edited this post 12 years, 10 months ago.]
    • discuss.answer
      • 3749
      • 24,544 Posts
      It looks like this:

      doodles core path: /var/www/html/doodles/core/components/


      should be

      doodles core path: /var/www/html/doodles/core/components/doodles/


      I think the second one is what the setting of your doodles.core_path System Setting should be. If that setting exists, it will be used by the code and the $defaultDoodlesCorePath will be ignored.

      When you're trying to set up a path, it can help to see if there's a file there or not:

      if (! file_exists($path)) {
         echo '<p>No file at: ' . $path . '</p>
      }
        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
        • 45374
        • 18 Posts
        Thank you, Bob Ray. You were right.

        This is where I messed up:

        doodles.assets_url - /doodles/assets/components/doodles


        I hadn't set up the assets url correctly in the settings.

        When I put it in the right way... my output became this:

        default core path: /var/www/html/modx-2.2.10-pl/core/components/doodles/
        doodles core path: /var/www/html/doodles/core/components/doodles/
        Script Properties: Array ( ) 
        
        dood object:
        object(Doodles)[25]
        ...
        
          • 3749
          • 24,544 Posts
          I'm glad I could help. Thanks for reporting back. smiley
            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
            • 38290
            • 712 Posts
            I've been working on generators lately, and have something I'd like to try in a effort to make tutorials easier to follow.
            While it is important to digest the code examples, sometimes you spin your wheels on a silly syntax error. I've done this myself several times with the Doodles tutorial.
            Anyways the idea is to you either Yeoman or git branches to have "checkpoints" in your tutorial that can be skipped too.
              jpdevries
              • 3749
              • 24,544 Posts
              I have to confess that after witnessing the frustration of others, I've never worked the Doodles tutorial, although I've looked at parts of it. Part of the reason I wrote the CreateXdpoClasses extra was to help people avoid the hassle of going through all those steps just to use a simple custom table with xPDO.

              I've got a rough, but working, extra called ClassExtender for extending MODX classes. It's very slick -- basically, you pick the class, specify a couple class names, and edit the schema and it does the rest (including adding the package to extension_packages).

                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
                • 45374
                • 18 Posts
                I can see why you went that route. This thing is driving me crazy.

                Now I am stuck at this point:

                $doodles = $modx->getCollection('Doodle');
                $output = count($doodles);


                $doodles comes back null. There's no error message or warning. It just fails silently so that I have no indication of where to look to fix it...! There's so many steps in the tutorial... and so few means of checking that you are still on track...!
                  • 45374
                  • 18 Posts
                  Aha... it was this part. Somehow I missed it. Argh!

                  $this->modx->addPackage('doodles',$this->config['modelPath']);
                    • 38290
                    • 712 Posts
                    There a a couple places in that tutorial I've often tripped up on also. Perhaps some more editing would make it easier to follow, but with any length code based tutorial there is the potential of getting snagged up. I'm not sure how much of the target audience is on git, but I've been wondering if creating branches as "checkpoints" for the tutorial would make sense.

                    That way you could say things like ok your code should look like this but to skip ahead and cheat:
                    git checkout step-2
                      jpdevries