We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15309
    • 30 Posts
    Is there any way to debug php codes line-by-line in modx, If any error catched at compile time, it is hard to find errors without filename and line number because modx doesnot displaying accurate error messages as php compiler do. Is there any alternate way to display php errors and warnings in modx. If anyone knows about it, please give some time to answer it. Your help will be greatly appreciated.
      • 21257 MODX Staff
      • 730 Posts
      I also like writing snippets in my editor, so I can step through them and do everything my IDE is capable of.

      Two other techniques I have used, depending on the situation:

      a) configure PHP to log it’s errors to a file, and just leave an SSH window up doing `tail -f error_log` (or whatever the path/name of your error log is) so you can watch the messages in realtime - not practical if you don’t have command-line access

      b) The MODx "System Events" log (see Reports > System Events in the Manager)
      MODx will automatically log some (all?) php errors from Snippets (or maybe the parser in general? I don’t know under what conditions - certain error types or notifications or what-not.. maybe look in there and see if there’s anything helpful already being logged.)

      You can also log your own messages to MODx’s ’System Events’ log - I’m using this technique right now to debug a snippet on a page being called by an external web service (FoxyCart). This is impossible to step through because I’m not the one initiating the page request, and I am also unable to get php logging to a file. So I just keep logging stuff, reading the logged events and I am getting through it. Slower than I’d like, but it works ;-)

      $modx->logEvent(__LINE__, 1, "subscribe ... ", '{{MailBuildSubscribe}}');
      


      The first parameter is "event id", which is arbitrary as far as I can tell. I just set it to the line number in the snippet to make it easy to keep track of.

      The second parameter is "type". This is from the in-line code documentation: Types: 1 = information, 2 = warning, 3 = error

      The third parameter is "message" - any string you want to log.

      The fourth parameter is "source" - again, any string you want to help you figure out the source of the log entry. (In retrospect, I may put my line number in this parameter next time, and use more meaningful event ids.)
        Mike Schell
        Lead Developer, MODX Cloud
        Email: [email protected]
        GitHub: https://github.com/netProphET/
        Twitter: @mkschell