Zend Framework debug console... chicken / egg problem
Posted: Mon Jun 02, 2008 4:09 pm
I have decided to create a controller plugin / action helper for my zend framework application that renders a debug console below my application if so told by my config object. I'm trying to make it show all the css / scripts / etc. that are being used in the current request. The problem is that styles are added in the view:
Example view (using layout)
Layout looks like:
My problem is that since the links / scripts are added in the view, when my plugin requests the view object, the view template hasn't been rendered, so it can't see the newly added scripts / stylesheets. OK, no problem, I'll just make my plugin come later in the plugin stack...
bootstrap.php
Well that works just great except that now the view is rendered before the debug plugin gets to add its view rendering to the debug placeholder... so wtf do I do??
My plugin (in case u wanted to see it)
Example view (using layout)
Code: Select all
<!-- add a css file and javascript to this layout -->
<?= $this->headLink()->appendStylesheet($this->url(array('stylesheet' => 'base.css'), 'stylesheets')); ?>
<?= $this->headScript()->appendFile($this->url(array('script' => 'image-gallery.js'), 'javascripts')); ?>
<h2>Image Gallery</h2>
<ul class="gallery">
<?= $this->partialLoop('image.phtml', $img) ?>
</ul>Code: Select all
<?= $this->doctype('HTML4_STRICT'); ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?= $this->headTitle("Some Application Title"); ?>
<?= $this->headStyle(); ?>
<?= $this->headScript(); ?>
<?= $this->headLink()->appendStylesheet($this->url(array('stylesheet' => 'base.css'), 'stylesheets')); ?>
</head>
<body>
<div id="container">
<h1><?= $this->link('Home'); ?></h1>
<?= $this->layout()->content; ?>
</div> <!-- /container -->
<?= $this->placeholder('debug'); ?>
<!-- start javascripts (loaded at end of body so as not to hold up the rest of the page during load) -->
<?= $this->inlineScript(); ?>
<!-- end javascripts -->
</body>
</html>
bootstrap.php
Code: Select all
// ..snip
$front->registerPlugin(new Q_Controller_Plugin_Debug($view), 1000); // viewRenderer is at like 99 or 100, so set to 1000 to make sure it comes as late as possible
// ..snipMy plugin (in case u wanted to see it)
Code: Select all
class Q_Controller_Plugin_Debug extends Zend_Controller_Plugin_Abstract
{
protected $view;
public function __construct(Zend_View_Abstract $view) {
$this->view = $view;
}
public function postDispatch(Zend_Controller_Request_Abstract $request) {
$front = Zend_Controller_Front::getInstance();
$this->view->headLink()->appendStylesheet($this->view->url(array('stylesheet' => 'debug.css'), 'stylesheets'));
$output = $this->view->render('elements/debug.phtml');
$this->view->placeholder('debug')->set($output);
}
}