We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8416
    • 173 Posts
    Hi,
    I just like to know how do you debug snippet code in general in a MODx environment with tools such as PhpED or Zend Studio. What would you advise.
    Thanks
      • 21257 MODX Staff
      • 730 Posts
      I use Zend Studio, and I put the code in an external file, and include it from the MODx snippet.
      Then I have all of the code debugging functionality Zend gives me. When you’re finished, you can move the code into MODx after, or just leave it in an external file, whichever suits the situation.
        Mike Schell
        Lead Developer, MODX Cloud
        Email: [email protected]
        GitHub: https://github.com/netProphET/
        Twitter: @mkschell
        • 8416
        • 173 Posts
        Thanks for the quick reply!
        However, I have one more question, how do you include it from MODx snippet?

        I created a snippet with this contents:

        <?php
        include("MySnippet.php");
        ?>

        Now when I run the snippet from Zend I can’t step into MySnippet code. Sorry for this newbie question but any help is appreciated.
        Thanks again.
          • 21257 MODX Staff
          • 730 Posts
          I’m using the Zend toolbar in Firefox to control debugging. All I have to do is set a breakpoint in the file I want to debug, start debugging in Firefox, and Zend kicks into action. I have Zend set to pause at the beginning of execution, so it always starts paused on the first line of the MODx front controller (index.php).. There are many ways of stepping through the code as you know, but my point is that, even if a file is included via a Snippet, and I have a breakpoint set in that file, Zend will pause at that breakpoint.
          I’m using Zend Studio v 5.5, internal debugging mode.
            Mike Schell
            Lead Developer, MODX Cloud
            Email: [email protected]
            GitHub: https://github.com/netProphET/
            Twitter: @mkschell
            • 8416
            • 173 Posts
            Thanks a bunch. That helped!

            Eric.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Wow... and I just put a lot of echo statements in my code! grin grin
                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
                • 8416
                • 173 Posts
                More question about debugging snippet with input forms...

                Let’s say that I have a document with the following contents:

                [[NewsPublisher? &folder=`2` &formtpl=`FormBlog` &footertpl=`Comments` &makefolder=`1` &rtcontent=`tvblogContent`]]

                Now I have want to debug and step tru the snippet "NewsPublisher". So I put the code from the "NewsPublisher" in an external file, and include it from the MODx snippet. I start debugging from the MODx front controller (index.php), however I can’t get to my input form. Should I "hard-code" the snippet invocation from the index.php?
                I don’t know if I’m explaining properly sad

                Thanks
                  • 21257 MODX Staff
                  • 730 Posts
                  Quote from: echaland at Jan 08, 2008, 08:30 AM

                  however I can’t get to my input form
                  This is the only part I don’t understand. Maybe you can explain in more detail what you’re expecting to happen? Where is the input form located, and what are you hoping to see in the debugger?
                    Mike Schell
                    Lead Developer, MODX Cloud
                    Email: [email protected]
                    GitHub: https://github.com/netProphET/
                    Twitter: @mkschell
                    • 8416
                    • 173 Posts
                    Sure, let me try to explain...
                    Let’s say for instance I have a document "Add Blog" whose content invokes the "[[Newspublisher with parameters]]" snippet. I want to be able to step into the snippet source code itself. So, I copy the contents of the "Newspublisher" snippet into an external file for debugging. The snippet now simply includes the external source code file reference.
                    The problem is that I need to start debugging in index.php and then I have to invoke the document "Add Blog" to eventually step into the source code of the snippet...
                      • 21257 MODX Staff
                      • 730 Posts
                      I see.. the thing is that you can’t exactly invoke the "Add Blog" document inside the debugger, at least not in the way I think you’re thinking about it.
                      Every MODx page/document is just an invocation of the front controller script, which calls the document parser etc.. and the "page" or "document" is assembled from the various bits and pieces by the document parser. So you start out at the document parser in your debugger, and you could step line by line through the whole MODx parsing, though it would take a long long time and you would likely get lost (I would). Eventually you would end up at the part in the code that reads the snippet from the database, and then executes it. But even then, just stepping through the code, the debugger would step over the "eval" statement that executes the snippet, and you’d miss the snippet code entirely. So you have to set a breakpoint in the file itself - it’s the only way for the debugger to catch anything inside the eval statement (ie running the snippet).
                      So again, don’t worry about debugging "the document", because it’s the MODx parser that’s creating it on the fly, and stepping through the parser is probably more than you want to get into.
                      Just set a breakpoint in your included file, and Zend should stop at it when you press "Go".
                      This works for me.. maybe it’s possible that it won’t work on your system(?) I hope I’m understanding things right and that you can get it working too.
                        Mike Schell
                        Lead Developer, MODX Cloud
                        Email: [email protected]
                        GitHub: https://github.com/netProphET/
                        Twitter: @mkschell