How to Call $this->session->flashdata Globally - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How to Call $this->session->flashdata Globally (/showthread.php?tid=52884) |
How to Call $this->session->flashdata Globally - El Forum - 06-30-2012 [eluser]fjamal[/eluser] I found a solution that calls $this->session->flashdata('temp_msg') globally. However, i'm not sure if its the right solution or not. 1. The function add within home controller i.e. http://...../ci_folder/home/add has the following code: Code: $this->general_lib->set_temporary_message('Inserted Successfully'); Implementation of set_temporary_message: Code: //Holds a message to be shown after redirect. For example, a success message as "Good Job! Registered Successfully". Hence, home controller extends MY_Controller 2. Once page get redirected to the default page, the message shows up. $this->session->flashdata('temp_msg') is in a custom config file as shown in step 3. 3. Write custom config file, called globals.php: Code: $CI =& get_instance(); 4. The library below set the config variables as globals, surely, i autoload the library: Code: class Globals { 5. I call $TEMPORARY_MSG anywhere within the view. It either has a message or empty string. 6. As you can see, whenever i need to set flashdata, all i have to do is setup my message: Code: $this->general_lib->set_temporary_message('Any Message You Want'); Is this a good idea? How to Call $this->session->flashdata Globally - El Forum - 06-30-2012 [eluser]fjamal[/eluser] I believe its not a good solution. I could just call Code: echo $this->session->flashdata('temp_msg'); How to Call $this->session->flashdata Globally - El Forum - 06-30-2012 [eluser]skunkbad[/eluser] If all you want to do is display a confirmation, why not just append a query string variable to your URL that you are redirecting to. Code: ?conf=1 How to Call $this->session->flashdata Globally - El Forum - 06-30-2012 [eluser]fjamal[/eluser] Hence, i just moved all my globals to MY_Controller's constructor: Code: $my_globals['title'] = 'Sample Site'; I was trying to find away not to repeat Code: $this->session->flashdata(....); How to Call $this->session->flashdata Globally - El Forum - 08-01-2012 [eluser]fjamal[/eluser] LATEST: I just changed my globals to defined constants. I moved Code: $this->session->flashdata('temp_msg'); Thanks |