Welcome Guest, Not a member yet? Register   Sign In
Setting flashdata in the destructor
#1

[eluser]Majd Taby[/eluser]
Hi, I'm creating a messaging library, so that my code can relay messages to the user. I'm setting flashdata so that the messages are contained in some form until they can actually be used.

Here's the problem:
Throughout my code, I'm building the array of the messages (There could be more than one message per-page). So the best way i found to set the flashdata was in the destructor, where all the messages are already added.

How can i delay the output until after the destructor?



p.s. If it has anything to do with output buffering, then i can't figure it out..i've been adding ob_start() and ob_end_flush() everywhere...i've never needed them so i don't exactly know where they go in the codeigniter system.

EDIT: I found the following solution:

Code:
function add($type,$message){
        $this->messages[$type]['messages'][] = $message;
        $messages = $this->CI->session->flashdata('jtabymessages_'.$type);
        $messages[$type][] = $message;
        $this->CI->session->set_flashdata('jtabymessages_'.$type,$messages);
    }

However, it's not the most elegant / efficient solution...what do you guys think?




Theme © iAndrew 2016 - Forum software by © MyBB