my_model->do_something(); * set_flash('Did something with my model!'); * redirect('/mysite/index'); * * In view file: * * * * * ---- REQUIREMENTS ---- * * This plugin needs: * - The session class (must be loaded before any view) * - The script.aculo.us library (optional but default) * * * ----- REFERENCE ---- * * bool set_flash ( string message, array options ) * @params message: The message to be displayed. * @params options: An associative array containing a list of * optional settings. See below for details. * @returns: TRUE on success, FALSE on failure. * * string get_flash ( array options ) * @params options: An associative array containing a list of * optional settings. See below for details. * NB. Any options set in the get_flash will * override any that were set in the set_flash. * @returns: HTML/Javascript to display message * * * ----- OPTIONAL PARAMETERS ---- * * -> div_id => 'flash' * ID of containing div * * -> duration => '2000' * Length of time (ms) to display message before fading. * * -> auto_fade => 'true' * Automatically fade message after duration. * * -> image => '/images/close.gif' * Path of image to display for user to click to dismiss message box. * e.g. a red cross or something similar. Image is highlighted on mouseOver * and cursor is set to pointer. * * -> toggle => 'new Effect.toggle("$divID", "appear", { duration: 0.5 });' * Javascript to run when close img is clicked. If you don't wish to use the * default script.aculo.us effects, modify this. * * -> on_timeout => 'new Effect.Fade("$div_id")' * Javascript to run after `duration` ms have passed. * * -> Any other variable specified under the BEGIN DEFAULT BLOCK in the code below. **/ # # Set the flash message, persistent over a session # function set_flash($message, $opts='') { $CI =& get_instance(); if ( ! is_object($CI->session) ) show_error('Session class must be loaded!'); if ( ! is_string($message) ) show_error('Error: First parameter must be a string!'); return $CI->session->set_userdata( array( 'flash_message' => $message, 'flash_opts' => $opts, ) ); } # # Get the flash message and clear it from the session # function get_flash($opts='') { $CI =& get_instance(); if ( ! is_object($CI->session) ) show_error('Session class must be loaded!'); # Check for any messages $message = $CI->session->userdata('flash_message'); $flash_opts = $CI->session->userdata('flash_opts'); if ( $message == '' ) return ''; # Clear our messages $CI->session->set_userdata( array( 'flash_message' => '', 'flash_opts' => '', ) ); # BEGIN DEFAULT BLOCK -- all of these variables can be overridden by opts $auto_fade = true; $close_button = false; $duration = 1000; $div_id = 'flash'; $close_style = 'position:relative; float:right; cursor:pointer'; $image = '/images/close.gif'; $fade_style = 'filter:alpha(opacity=50); -moz-opacity:0.5;'; $normal_style = 'filter:alpha(opacity=100); -moz-opacity:1;'; $toggle = 'new Effect.toggle("'.$div_id.'", "appear", { duration: 0.5 });'; $mouse_over = 'this.style.cssText = "'.$normal_style.'"'; $mouse_out = 'this.style.cssText = "'.$fade_style.'"'; $on_timeout = 'new Effect.Fade("'.$div_id.'")'; # END DEFAULT BLOCK # extract any overrides from arguments if ( is_array($flash_opts) ) extract($flash_opts); if ( is_array($opts) ) extract($opts); if ( $auto_fade ) $timeout = "setTimeout('$on_timeout', $duration);"; else $timeout = ''; $ret = ''; if ($close_button) { $ret .= "
"; $ret .= " Close"; $ret .= "
"; } $ret .= "

$message

"; $ret .= ""; $ret .= ""; return $ret; } ?>