Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 64 additions & 17 deletions flash_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,49 +25,80 @@
* @category Helpers
* @author Chris Monnat (https://github.com/mrtopher)
* @commiter Obedi Ferreira (https://github.com/obxhdx)
* @modifier Eric Haughee (https://github.com/ehaughee)
* @link http://www.christophermonnat.com/2009/05/building-applications-using-codeigniter-part-3-helpers/
*
*/


/**
* Display formatted flash message.
* Display formatted flash message. Compatible with
* a CodeIgniter redirect() and loading a view.
*
* @access public
* @param string|array
* @return string
*/
function display_flash($name)
function flash($name = 'flash_message')
{
$CI =& get_instance();

if($CI->session->flashdata($name))
{
$flash = $CI->session->flashdata($name);
if($CI->session->flashdata($name))
{
$flash = $CI->session->flashdata($name);

if (is_array($flash['message'])) {
$msg = '<div class="' . $flash['message_type'] . '">';
if (is_array($flash['message']))
{
$msg = '<div class="alert alert-block alert-' . $flash['message_type'] . '">';
$msg .= '<button class="close" data-dismiss="alert">×</button>';

foreach ($flash['message'] as $flash_message) {
$msg .= $flash_message . '<br />';
}
foreach ($flash['message'] as $flash_message)
{
$msg .= $flash_message . '<br />';
}

return $msg . '</div>';
} else {
return '<div class="' . $flash['message_type'] . '">' . $flash['message'] . '</div>';
}
}
return $msg . '</div>';
}
else
{
return "<div class='alert alert-block alert-{$flash['message_type']}'>
<button class='close' data-dismiss='alert'>×</button>{$flash['message']}
</div>";
}
}
else if (isset($_SESSION["flash"]) && !empty($_SESSION["flash"]))
{
/**
* This code derived from: http://codeigniter.com/wiki/Simple_FlashNotice_helper/
*/

$flash = $_SESSION["flash"];
unset($_SESSION["flash"]);

$msg = '';
foreach($flash as $key => $val)
{
$msg .= "<div class='alert alert-block alert-$key'>
<button class='close' data-dismiss='alert'>×</button>
$val
</div>";
}

return $msg;
}
}

/**
* Save provided message as a flash variable.
* Save provided message as a flash variable for display
* after a CodeIgniter redirect (redirect()).
*
* @access public
* @param string
* @param string
* @param string
* @param boolean
*/
function set_flash($name, $message_type, $message, $redirect=FALSE)
function setflash($message, $message_type, $redirect = FALSE, $name = 'flash_message')
{
$CI =& get_instance();
$CI->session->set_flashdata($name, array('message_type' => $message_type, 'message' => $message));
Expand All @@ -76,5 +107,21 @@ function set_flash($name, $message_type, $message, $redirect=FALSE)
redirect($redirect);
}


/**
* Save provided message as a flash variable for display
* after loading a view ($this->load->view()).
* Source: http://codeigniter.com/wiki/Simple_FlashNotice_helper/
*
* @access public
* @param string
* @param string
*/
function setviewflash($error = "An error has occurred", $type = "error")
{
$_SESSION["flash"][$type] = $error;
}

/* End of file flash_helper.php */
/* Location: ./application/helpers/flash_helper.php */
?>