Hi, I am trying to debug modx snippets using XDebug in Visual studio Code. VSCode is configured via tutorials and “Listen for Xdebug” works for example for index.php.
But when I insert php code in external file and set snippet as static for this file. Debuging is not working.
Another thing is if I insert xdebug.start_with_request=yes to php.ini (xampp) modx page will not load. Not sure if this config is necessary or not. Please help.
I’ve debugged through index.php, but it’s usually pretty tedious to click through all the steps to get to the offending code.
I often debug by instantiating MODX in an external script, and then including, and instantiating instances of classes and calling their methods, or in situations like yours, calling $modx->runSnippet() with an appropriate set of properties.
In both cases, you can step through the problem code and place breakpoints wherever you need them.
I get it. I would run this in PhpStorm where xDebug is already enabled. It will do remote debugging, but I usually debug on a local install.
I often need to adjust the code and the properties between debug runs.
What I normally do is have the snippet code in a file, set up the $ScriptProperties array then “include” the file. This will often find problems in the snippet that have nothing to do with the rest of MODX.
If I need to see the snippet interacting with the install, I instantiate MODX (the version in the install), set up the $scriptProperties array, and call $modx->runSnippet();
The down side of your method for me would be having to go to the Manager and manually adjust the snippet’s default properties, though it sounds like a great method when you need to do remote debugging.
This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.