Codeigniter flashdata - am I using it correctly?
Session data is available anywhere in your application, at any time. Calling it directly from a view file is proper, and so it setting it in a Controller.
There's no need at all to pass it as data with $this->load->view()
- it's redundant. Why assign it to the flashdata in the first place in that case?
The way you're doing it is correct.
EDIT: I just saw you are setting it in the Model instead of Controller - which is highly debatable. I would suggest returning a value from your Model call, and setting the message based on it in your Controller instead.
$myArr = array('value 1', 'value 1');$this->session->set_flashdata('myArray', $myArr);
In the view,
print_r($this->session->flashdata('myArray'));
I just save it in an array and pass it to the view :)
$data['wow_list'] = $this->Wow_model->getWow($uid); $this->session->set_flashdata('message', 'Done. You have added new task.'); $data['flash_message'] = $this->session->flashdata('message'); $this->load->view('wow/index', $data);
View
<?= $flash_message ?>
Data is passed from the controller to the view by way of an array or an object in the second parameter of the view loading function.