Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] set_flashdata in Model?
#1

[eluser]David Rothera[/eluser]
I have a model that does a query and then set's one of three possible flashdata messages regarding the outcome of the query.

The problem I am having is that it is not keeping the flashdata outside of the Model, I am using a redirect() so I know that there is definitely a new server request and the variable is not being used and therefore not destroyed.

Any suggestions?
#2

[eluser]Craig A Rodway[/eluser]
Have you tried a few echo var_export($_SESSION, TRUE); lines at several places within your code to see if the data is being set?

Also could you post the code in your model that you're using?
#3

[eluser]David Rothera[/eluser]
Just before you replied I was going to edit the initial post, I have put an 'or die()' on the end of the set_flashdata and it seems that it cant actually execute set_flashdata for some reason.
#4

[eluser]David Rothera[/eluser]
If I change it from flashdata to userdata it still can't do it, for some reason I cant set session data of any kind from within the model. Sad

EDIT: The code from the model, by messing with different debugging I have found that if I set the flash/userdata inside the model and then echo it out in the model as well it is fine however you cannot access any session data from outside the model.

EDIT2: I have solved it, I replaced the redirect with a plain anchor and it works now.
Code:
function addUser($data)
    {
        $query = $this->db->query("SELECT `id` FROM (`users`) WHERE `email_address` = '$data[email_address]'");
        if ($query->num_rows > 0) {
            $this->session->set_flashdata('message', 'Error: The email address is already active in the system!');
            return 0;
        }
                
        if ($this->db->insert('users', $data)) {
            $this->session->set_flashdata('message', 'Notice: User added successfully.') or die('waa waa2');
            return 1;
        } else {
            $this->session->set_flashdata('message', 'Error: There was an error adding the user, please try again.') or die('waa waa3');
            return 0;
        }
    }




Theme © iAndrew 2016 - Forum software by © MyBB