Welcome Guest, Not a member yet? Register   Sign In
Odd flash issue for me...
#1

[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?
#2

[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.
#3

[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?
#4

[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'] = ..
#5

[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');
#6

[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.




Theme © iAndrew 2016 - Forum software by © MyBB