Tagged pr

Use the awesome dBug class in CakePHP

If you program in PHP, you’re probably annoyed by var_dump, because the output is really difficult to read, especially if the var is a nice big object or array. If you’re used to working in CakePHP, you probably use pr() because it’s slightly better than var_dump.

At work, however, we use a class called dBug, which gives you color-coded variable output with collapsible hierarchy, etc. In other words, a pretty awesome debugging tool. To get this functionality in your Cake app, just do the following:

  1. Download dBug.php from the author’s site and put it in your app/ directory.
  2. In your app_controller.php (or whatever your base class is), add the following line:
    [cc lang=”php”]include_once(“dBug.php”); [/cc]
  3. You can get beautiful dBug output by calling the following in a model, controller, or even view:
    [cc lang=”php”]new dbug($myvariable);[/cc]

That’s it! You’ll probably never use pr() again 🙂