Jonathan Lahijani Posted June 11 Share Posted June 11 Oftentimes I'll have little scripts that bootstrap ProcessWire and do various things. These scripts usually echo out information. However, I'm beginning to start using the Console feature of TracyDebugger as somewhat of a replacement. One thing I'm wondering is if a snippet can work nicely whether I run it with the php command vs. the TracyDebugger console. So for example, I have this in /site/templates/TracyDebugger/snippets/test.php: <?php namespace ProcessWire; if(!defined("PROCESSWIRE")) include(dirname(__FILE__).'/../../../../index.php'); d($pages->get(1)); If I run that in TracyDebugger Console, it outputs nicely due to the d() function. However if I run it with php directly like this: php site/templates/TracyDebugger/snippets/test.php ... it won't output anything. I'm guessing this is because (a) TracyDebugger doesn't run in CLI mode and (b) TracyDebugger is disabled in this state given my settings and (c) the d() function doesn't run in CLI mode. Is there some slick way to do this, or some alternative best practice? Link to comment Share on other sites More sharing options...
adrian Posted June 11 Share Posted June 11 If I enable guest dumps (via the button on the panel selector) and use bd() instead of d() then after calling a script via the command line, I can reload the site in the browser and the bd() calls will be displayed. Does that help? The only other solution I can think of at the moment is to maybe check if the snippet is called via the CLI and convert d() calls to print_r() automatically? I've done some quick experiments on that idea and seems fairly useful. By the way - just making sure that you're familiar with the Console panel's "Code Prefix" settings field for adding that: <?php namespace ProcessWire; if(!defined("PROCESSWIRE")) include(dirname(__FILE__).'/../../../../index.php'); block automatically to each snippet. 1 Link to comment Share on other sites More sharing options...
Jonathan Lahijani Posted June 11 Author Share Posted June 11 4 minutes ago, adrian said: convert d() calls to print_r() automatically Yea I was thinking if that was native functionality, it would feel seamless. Link to comment Share on other sites More sharing options...
bernhard Posted June 11 Share Posted June 11 What I always do is to write those scripts in an object oriented way right from the beginning. That's as easy as adding one method to the Site.module.php Then I add $site->doSomething() to ready.php and RockFrontend will live reload the page as soon as I update Site.module.php and I'll see all the dumps in Tracy. No need to switch screens. No need to switch windows. No need to use the mouse. Just write code, save, see the dumps. And once everything works, everything is just an api call away! And, of course, it's under GIT. $site->party() ? PS: And if you happen to need that for a cron or similar: <?php include "index.php"; $site->party(); 1 Link to comment Share on other sites More sharing options...
adrian Posted July 11 Share Posted July 11 On 6/11/2024 at 11:56 AM, Jonathan Lahijani said: Yea I was thinking if that was native functionality, it would feel seamless. Hi @Jonathan Lahijani - this automatic conversion for d() and db() calls to echo/print_r is now available in the latest version. Hope it helps. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now