Welcome Guest, Not a member yet? Register   Sign In
Duplicate flashdata
#1

[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)
Code:
Login failed!

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;
        }
    }
}
#2

[eluser]Glazz[/eluser]
Hmmm i tried your function and it worked as expected..

Try to see if you are not echoing anything that are on the flashsession or something..

Post your controller here please.




Theme © iAndrew 2016 - Forum software by © MyBB