Interactive Plugin For CakePHP Console and DebugKit
I teased this on twitter last week, so here's the official release. The interactive plugin is a super easy way to run code against your Cake app. You can use it either through a custom panel in the DebugKit or from the command line as a shell.
Download
Instructions
I'll skip the install instructions, since they're included in the README. It's pretty easy to install. If you're using the latest stable release of the DebugKit you do need to apply a patch for better plugin handling. That fix is already in the trunk, so it's not a dirty hack.
What It Can Do
Let's get right to the good stuff.
Run Simple PHP
Pretty much any simple PHP commands will run:
10 % 4 //returns 2 is_array(49) //returns false
Run SQL
SELECT id FROM users WHERE email = 'test@test.com' //returns the id of the user UPDATE posts SET published = false; //returns "No results found.", but does the update.
Use Cake Functions
__('Test Message', true) //returns the translated text matching the msg id for your current language.
Configure::write('Config.language', 'es');
__('Test Message', true); //returns the translated text in Spanish.
Use Cake Libs
Security::hash('my_pAssw0rd', null, true) //returns the hashed password
Set::extract('/id', array(array('id' => 3), array('name' => 'test', 'id' => 4))) //array(3, 4)
Use Cake Helpers
$html->link('Posts', array('controller' => 'posts')) //the html code for the link and the link itself
$form->input('Post.title'); //the html code for the field and the field itself
Use Your App Code
Post::find('first') //The first record from your posts table
User::findById(3) //The user record for id 3
Debugging
If you have a command that isn't returning the results you expect, you can turn on debug first:
Configure::write('debug', 2);
User::findByIdd(3) //will show error output
Notes
When using through the DebugKit you can stack commands, just separate them with a ";". However you can't define a variable in one command then use it in another. For example this doesn't work:
$i = 10; $i ++; echo $i;
You'll also notice I never explicitly declared any of the models I was using. The plugin does this automatically. You can write your model calls statically or just pretend you have an instance. These are all the same and will work:
Post::find('first');
$Post->find('first');
Post->find('first');
$this->Post->find('first');
The DebugKit = Awesomeness
Like most of you, I read this post from Mark Story on the new JavaScript for the DebugKit. Just reading that post, you don't get a full appreciation for how much work he (and others) have put into it. The JavaScript lib is virtually it's own mini-framework. Everything I needed to create this was already included - Ajax, Event handing, Elements...Really great stuff.
That's About It
Let me know if you hit any commands you want to run that aren't working. I tried to cover most of the basics.

19 Comments
Great plugin.. I've wanted to have something like this for a while to test cake calls (without debug()-ing everything within views). I haven't had a chance to test the debug_kit integration, but in terms of the console plugin, it works great. I wish there was a way to cycle through past commands (e.g. up/down shows previous lines); though this hasn't been an ability for me on any cake console scripts available. Would be a nice addition, if possible in later revisions though.
Keep up the good work.
Also, with your patch is it your intention to display "Interactive.interactive" as the menu item under DebugKit, or do you want it to show as "Interactive"?
if (strpos($className, '.') !== false) {
list($plugin, $className) = explode('.', $className);
}
It seems if you put use $panel in place of $plugin, the key is adjusted accordingly.
Well, actually, it hasn't :P. I tried (with DebugKit):
3 + 4;
And it returned:
3 4
false
Then I tried 10 % 4 and Article->find(4), and it worked. But I must say you scared the hell out of me with my first test :-). It was like "Woooww! This is... shit :P.
Very helpful. Thank you very much!
can you replace views/elements/interactive_panel.ctp, line 2 with:
echo $form->create('Interactive', array('url' => array('admin' => false, 'controller' => 'interactive', 'action' => 'cmd'), 'id' => 'interactive-form'));
so i can use this great thing in my admins!
var $components = array('Cookie','Acl','Auth','AuthExtension','Email','RequestHandler',array('DebugKit.Toolbar' => array('panels' => array('Interactive.interactive'))));
i got this error:
Warning (2): Illegal offset type [CORE\cake\libs\set.php, line 905]
if i manually add the panel to toolbar component from debug kit:
var $_defaultPanels = array('session', 'request', 'sqlLog', 'timer', 'log', 'memory', 'variables', 'Interactive.interactive');
i got this error:
Fatal error: Class 'Interactive.interactivePanel' not found in C:\dev\colombia\LugoHermanos\branches\tienda\app\plugins\debug_kit\controllers\components\toolbar.php on line 167
so i really dont know what to do =P please help!
Debug timer infoMessageStart Time
(ms)End Time (ms)Duration (ms)Core Processing (Derived)012081208Component initialization and startup1208
124335
and nothing else, i double check my core debug and is set to 2
http://img38.imageshack.us/img38/1629/debug.gif
Add new comment