CodeIgniter Forums
Odd flash issue for me... - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Odd flash issue for me... (/thread-9755.html)



Odd flash issue for me... - El Forum - 07-07-2008

[eluser]internut[/eluser]
Ok I'm going nuts hours later I have to post.

This is working fine:

Code:
$this->session->set_flashdata('sys_message', 'User Updated');
// redirect("/users/edit/$_POST[id]/");
redirect("/users/page/");

Its showing up when redirected to:

/users/page/

If I uncomment out the line above, and comment out the redirect to /users/page/ it will not display the flash data msg.

Why? I'm going nutso Smile Why is /users/page/ finding the flash fine and /users/edit/1/ for example not?


Odd flash issue for me... - El Forum - 07-08-2008

[eluser]flojon[/eluser]
You've probably missed calling
Code:
$this->session->flashdata('sys_message');
in the edit function. This is how you retrieve your flashdata.


Odd flash issue for me... - El Forum - 07-08-2008

[eluser]internut[/eluser]
I do have it and I'm getting strange behavior.

In:

/users/save/

I have:


Code:
$this->session->set_flashdata('sys_message', 'User Updated');
redirect("/users/edit/$_POST[id]/");

Then in:

/users/edit/ function I have:


Code:
$query = $this->db->query("SELECT * FROM users WHERE id='$id'");

if ($query->num_rows() > 0)  {
   $data = $query->row();
}

$data[sys_message] = $this->session->flashdata('sys_message');  // set system message to display

$this->load->view('users_edit',$data);

And its producing this error:

Fatal error: Cannot use object of type stdClass as array in C:\Program Files\WebServer\Abyss Web Server\htdocs\php\NEW\admin\system\application\controllers\users.php on line 217

If I move:

Code:
$this->load->view('users_edit',$data);

hmm now I notice it prolly has something to do with the $data array... Should i set that var in $data[] differently?


Odd flash issue for me... - El Forum - 07-08-2008

[eluser]flojon[/eluser]
[quote author="internut" date="1215551631"]
Code:
$data[sys_message] = $this->session->flashdata('sys_message');  // set system message to

hmm now I notice it prolly has something to do with the $data array... Should i set that var in $data[] differently?[/quote]

You've made a typo, change the line above to this:
Code:
$data['sys_message'] = ..



Odd flash issue for me... - El Forum - 07-08-2008

[eluser]Pascal Kriete[/eluser]
It is the data array.
Code:
$data = $query->row();

Assigns an object to $data, you're then trying to add a key.

Solution(s):
Code:
$data['row'] = $query->row();
// or
$data = $query->row_array();
// or
$data->sys_message = $this->session->flashdata('sys_message');



Odd flash issue for me... - El Forum - 07-08-2008

[eluser]internut[/eluser]
You guys rock.

Code:
$data->sys_message = $this->session->flashdata('sys_message');

Did not seem to work but this does:

Code:
$id = $this->uri->segment(3);  // Get user ID

$query = $this->db->query("SELECT * FROM users WHERE id='$id'");

if ($query->num_rows() > 0)  {
   $data = $query->row_array();
}

$data['sys_message'] = $this->session->flashdata('sys_message');  // set system message to display

$this->load->view('users_edit',$data);

Thanks a ton fellas.