-
Notifications
You must be signed in to change notification settings - Fork 7.6k
FlashNotice Helper
Category:Helper::Community | Category:Helper::FlashNotice
2007-10-27 File:FlashNotice_v1.0.zip - Uses PHP Sessions 2008-01-27 File:FlashNotice_v1.1_.zip - Uses CI sessions and view file for display
For those that use or would like to use those one-time informational messages that display after an action (like success, error, warning, info), I've made a helper for them.
Autoload the helper and now anywhere in your app you can add messages with this syntax:
FlashNotice::add("Your error message goes here", 'error');
FlashNotice::add("Your successful message goes here");
FlashNotice::add("You aren't allowed to do that", 'warning');
FlashNotice::add("Oops", 'error');
FlashNotice::add("I'm bringin' sexy back", 'info');
// the second parameter is an optional message type which can be
// any of the predefined values (info, success, warning, error)
// defaults to 'success'
Use those throughout your app and the helper stores them all in a Session var 'FlashNotice'
Then to display it in your view (preferably place this in a template header or something, so you only have to write it once)
// v1.0
FlashNotice::display();
// v1.1 - Optionally pass in the name of the FlashNotice view file you want to use
// this ends up being passed to $CI->load->view($viewFile)
FlashNotice::display($viewFile)
// if there are any messages it will compile and display them,
// then destroy the Session var that stored them.
// otherwise it won't print anything to the page
I have created a default look and feel for the display. To use it, just include the folder with the Css and images, and include the stylesheet in your html. v1.1 Additionally copy the included view file into your views folder
// v1.1 - FlashNotice View design code
// To get the messages in your custom design use the following code
$CI = get_instance();
$FlashNotice = $CI->session->userdata('FlashNotice');
foreach(FlashNotice::getTypes() as $type):
if( isset($FlashNotice[$type])
&& count($FlashNotice[$type]) > 0):
echo $type
foreach($FlashNotice[$type] as $message):
echo $message
endforeach;
endif;
endforeach;
// jQuery example of making the close buttons work
$(document).ready(
function()
{
$("#FlashNotice a.close").click( function(e){
e.preventDefault();
$("#FlashNotice").slideUp("slow", function() {
$("#FlashNotice").remove();
});
});
}
);
Hope some people find it useful.
As is, it's PHP5 only, since I used some things like private and static methods...sorry PHP4'ers!
2007-10-27 File:FlashNotice_v1.0.zip - Uses PHP Sessions 2008-01-27 File:FlashNotice_v1.1_.zip - Uses CI sessions and view file for display