Show SQL dump on redirect using CakePHP 1.3

Hi there!

An inconvenient i faced when i moved from CakePHP 1.2 to 1.3 is the fact of the debug SQL dump is now rendered as an element, this can be usefull if you want to customize or display it in any other place than in the bottom of the rendered output. But, in some situations, when you have an action without a view, those kind of actions usually redirect immediately after doing something, it means that the layout is never rendered, and as a consequence, the SQL dump too.

My solution is pretty simple and straight forward, i’ve just overrided the Controller::redirect() method in the AppController to detect if a debug was triggered (if any header was sent, it happens when you output something, in this case it’s sent by a debug() call), and if so, just render the sql_dump element, and stops.

The code is show below:

class AppController extends Controller {

    public function redirect ($url, $status = null, $exit = true) {
        if (headers_sent()) {
            $this->viewPath = 'elements';
            echo $this->render('sql_dump', false);
            if ($exit) {
                $this->_stop();
            }
        }
        parent::redirect($url, $status, $exit);
    }

}
Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: