We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2740
    • 95 Posts
    I created a simple snippet to send placeholders to eform but it just produced "Fatal error: Call to a member function setPlaceholder() on a non-object..."

    So I’ve gone back to the MODx Web Development book and tried the example shown in there.

    testtext Snippet:
    <?php
    $MODx->setPlaceholder("message1", "first");
    $MODx->setPlaceholder("message2", "second");
    return;
    ?>


    Test content
    [!testtext!]
    Before Placeholder1<br>
    [+message1+]
    Before Placeholder2<br>
    [+message2+]


    Yet even with this most basic test it is still producing a fatal error. As my snippet isn’t a function it doesn’t require global $modx; I disabled PHx for one test and still the same error. Does anyone know what is causing the error please?
      • 4041
      • 788 Posts
      Looks like the character case is wrong - instead of
      $MODx->setPlaceholder()

      should be
      $modx->setPlaceholder()
        xforum
        http://frsbuilders.net (under construction) forum for evolution
        • 2740
        • 95 Posts
        Thanks Breezer, that got rid of the fatal error.

        The placeholders do not work if PHx is enabled but at least the page now displays.
        • I never use the PHx plugin. It eats external placeholders. I suspect an error in the regular expression used in its own garbage collection function; it should only remove its own unused placeholders. If you must use the plugin, then instead of a placeholder in your content you’ll need to use a snippet with $modx->getPlaceholder(’placeholder-name’). The placeholder’s value is still in the placeholder’s array, it’s just that phx has eaten the tags. Ditto and Jot tpls using their own phx classes aren’t affected by this; it’s only when using placeholders in the main templates or content where the plugin causes the problem.

          As far as that book goes, I was given a copy and asked to put a review on my site. I read through the book and decided to follow my mother’s advice: "if you can’t say something nice, don’t say anything at all". It’s full of nasty errors like that; the author is a fine developer as the introductory chapters will show, but he doesn’t know any more about MODx than any reasonably competent developer would know after installing it and looking at it for a bit. I was a technical editor for its first edition, and cleared up the more obvious errors like $MODx instead of $modx, but the editors of this edition don’t know any more about MODx than the author does. While it covers the basics of MODx as a CMS reasonably well (other than referring to the wrong modules and plugins from time to time) it won’t do anybody much good if they’re trying to actually do anything besides show pages.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 2740
            • 95 Posts
            Thanks for the $modx->getPlaceholder(’placeholder-name’) tip which works well. I did try gettting it return two placeholders from one snippet but without any luck, so long term I’m going to have to drop PHx.

            I haven’t seen the second edition of the MODx Web Development book but the first edition was a disappointment, especially given its price. The brief sections on filtering, MODx API and the blog were quite helpful, but your comments are an accurate summary of its usefulness sadly.