I'm writing a simple web application using CakePHP version 1.2 (the latest) and am having an issue with displaying the flash message from the Session helper. In my layout, there exists the following code:
<?php echo $this->renderElement('flash'); ?>
Which renders the following element:
<?php if($session->check('Message.flash')): ?>
<?php $class = isset($error) ? 'contentError' : 'contentSuccess'; ?>
<div class="contentBlockWrapper <?php echo $class; ?>">
<div class="contentBlock">
<div id="flashMessage" class="flash">
<?php $session->flash(); ?>
</div>
</div>
</div>
<?php endif; ?>
The desired behavior is that, if there's a flash message to be displayed, that it be displayed at the above location within the DOM so that it will be styled and positioned as I wish.
The problem is that, if there is a flash message, CakePHP is rendering it immediately after the opening <body>
tag. Now, it also renders the containers described above in the correct location, but simply doesn't write the text where I want it.
I've tried flushing the output buffer into a variable within my view and echo'ing that, but to no avail. I've also read that some folks have tried using named keys to indicate the specific message they want displayed, but that isn't appropriate here because the text that I want to display is being displayed, just in the wrong location.
Any assistance would be appreciated - thanks!