[eluser]Carmichael[/eluser]
Hi. I've a function that I've named flash(). The function sets a flashdata and redirects the user.
The problem is if I redirect the user to the current page the flashdata prints two times. If I redirect the user to another page in the site and not the current page the flashdata prints once. The correct way.
Example
I am on the page login. I redirect the user to the same page.
Code:
flash('error', 'login', 'Login failed!');
Output
Code:
Login failed!
Login failed!
I am on the page login. I redirect the user to index.
Code:
flash('error', 'index', 'Login failed!');
Output (the correct way)
The function
Code:
if ( ! function_exists('flash'))
{
function flash($type='', $location='', $message='')
{
$ci=& get_instance();
$types = array('success', 'notice', 'error');
if (in_array($type, $types))
{
switch($type)
{
case 'success':
$ci->session->set_flashdata('message', '<div class="success">'.$message.'</div>');
redirect($location);
break;
case 'notice':
$ci->session->set_flashdata('message', '<div class="notice">'.$message.'</div>');
redirect($location);
break;
case 'error':
$ci->session->set_flashdata('message', '<div class="error">'.$message.'</div>');
redirect($location);
break;
default:
false;
break;
}
}
else
{
return false;
}
}
}