Skip to content

Simple FlashNotice helper

Derek Jones edited this page Jul 5, 2012 · 4 revisions

This is easy to use and simple FlashNotice Helper. It will help you to display error or notice message after some action. The message will be displayed only once and deleted afterwards.

To use it:

  1. save code below as "flash_helper.php" into your applciation/helpers directory.
  2. load helper using $this->load->helper("flash");

In your view:

  • To set notice:
setflash("Write notice","notice");
  • To set error:
setflash("Write error information","error");
  • To display notices on the page:
<?=flash();?>

You can use any other notice types in second parameter as this will result in class name of block element. Style #flash using CSS as you wish.

<?php
function flash() {
    $flash = $_SESSION["flash"];
    unset($_SESSION["flash"]);

    foreach($flash as $key=>$val) {
        $str .= '<div id="flash" class="'.$key.'">'.$val."</div>";
    }
    
    return $str;
    
}
function setflash($error="An error has occurred",$type="error") {
    return $_SESSION["flash"][$type] = $error;
}
?&gt;

You may use script.aculo.us and Prototype to automatically hide notice after few seconds.

e.g.

window.onload = setTimeout("new Effect.Fade('flash')",7000);

If you have any other ideas, please contact me at [email protected] or visit www.cleverleap.com.

Clone this wiki locally