public static function FlashMessage($msg)
{
$output = '';
$messages = explode(" ", $msg);
foreach($messages as $message)
{
$flashmessage = Session::get_flash($message);
if($flashmessage)
{
$output .= "<div class=\"alert-message $message\">";
if(is_array($flashmessage))
$output .= implode("<br />", $flashmessage);
else
$output .= $flashmessage;
$output .= "</div>";
}
}
return $output;
}
<?php echo Controller_Base::FlashMessage('success error info'); ?>
If your app is that complex, use the Theme class to bring some order to the chaos. I have apps with hunderds of views, but only a few page templates, which are completely partial based.
It may be more lines, but it's a more structural solution. Every app needs message management. This just generates a simple and standardized div structure that can be styles with css and js. Once written all I have to do is slow the class into place and I'm done.
It will also make all my modules portable, as they all interact with the user in the same way. Which means my time to market will improve, which in turn means I make more money. <!-- Begin messages -->
<?php
foreach (array('error', 'warning', 'success', 'info') as $type)
{
foreach(\Messages::instance()->get($type) as $message)
{
echo '<div class="',$message['type'],'-box">',$message['body'],'</div>',"\n";
}
}
\Messages::reset();
?>
<!-- End of messages -->
It looks like you're new here. If you want to get involved, click one of these buttons!