[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".
public function set_temporary_message($msg, $redirect_location = '') {
$this->session->set_flashdata('temp_msg', $msg);
redirect($redirect_location);
}
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();
$config['TEMPORARY_MSG'] = $CI->session->flashdata('temp_msg');
$config['TITLE'] = 'Sample Site';
$config['CSS'] = base_url().'rescources/css/style.css';
4. The library below set the config variables as globals, surely, i autoload the library:
Code:
class Globals {
function __construct($config = array()) {
if (is_array($config)) {
$CI =& get_instance();
$CI->load->vars($config);
}
}
}
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');
Page will be redirect automatically and message is shown to the user.
Is this a good idea?