I have a CodeIgniter web apps using foreach for user insert data then if the submitted data is successfully inserted, I created a flashdata message called sc_msg[]. But I have no idea how to call it on flashdata.
$user = $this->input->post('user', TRUE);
foreach ($user as $u)
{
$this->model->insert($u);
$sc_msg[] = '- User '.$u.'has been successfully registered<br>';
}
This is a code how I called it on my view.
<?php if ($this->session->flashdata('warning'))
echo $this->session->flashdata('message'); ?>
I wanted the message called like this :
- User
abchas been successfully registered- User
bcahas been successfully registered- User
qwehas been successfully registered- User
ewqhas been successfully registered
All sc_msg[] stored on message so I don't need to using FOR or FOREACH in the views to called it.
The problems is on my controller, I'm trying to set the message :
$this->session->set_flashdata('message', $sc_msg);
It's just print array, so I try to change $sc_msg into $sc_msg[] the result is error : Cannot use [] for reading.
I'm also trying to use foreach inside set_flashdata too and is failed. Unexpected foreach.
Then I'm trying to set the flashdata like this :
$this->session->set_flashdata('message', $sc_msg[0].$sc_msg[1]);
That is printed the result but only index 0 and index 1. Result :
- User
abchas been successfully registered- User
bcahas been successfully registered
There is another 2 messages not called for user qwe and ewq.
I have no idea how to call the message inside the flashdata. But, please don't give me for loop solutions. Thank you.