Welcome Guest, Not a member yet? Register   Sign In
flashdata not working as expected without redirect()
#1

[eluser]shelton_dev_guy[/eluser]
/** Moved from 'CodeIgniter Discussion' **/

Hi all,

I am developing an application that makes use of session->flashdata() for error/success messages on pages that use forms.

As the admin of the site, I also use the Profiler to track what queries are being executed. When I enabled the profiler, I noticed that some of the queries were not showing up. For example, when a user wants to update their profile, a db->update() function is executed.

After some digging, I realized that when I update the database, I set a flashdata variable and redirect to the same page, and the queries were not being saved to display in the profiler, but the flashdata never fails. When I modify my controller to load->view() instead of redirect(), the profiler shows the query, but now my flashdata is all messed up - it will never show until the next page load (sometimes 2 page loads.)

All I did was comment out the redirects, as shown below.

Controller:
Code:
if ($this->form_validation->run() !== false){
  $upd = $this->users_model->update_user($clean, $user->email);
  if ($upd){
    $this->session->set_flashdata('message', '<p class="success">Your profile has been updated.</p>');
    //redirect('auth/edit_user/'.$user->id);
  } else {
    $this->session->set_flashdata('message', '<p class="fail">Something went wrong, please try again or contact the helpdesk.</p>');        
    //redirect('auth/edit_user/'.$user->id);
  }
}

//this block executes if the form is not submitted, and/or after the validation succeeds/fails.
$data['content'] = "auth/edit_user";
$this->load->view('template', $data, false);

View:
Code:
<h1>Edit Your Profile</h1>
<div class="message">&lt;?php echo $this->session->flashdata('message');?&gt;</div>
//form stuff...

Other information that may be useful:

Config:
Code:
$config['sess_use_database'] = TRUE;

Is there a better (native CI) solution for success/error messages other than using session->flashdata()? I'm not opposed to adding an extra library or a function to one of my custom helpers, but it seems like this can be fixed without a bunch of excess coding.

Thanks,


Messages In This Thread
flashdata not working as expected without redirect() - by El Forum - 09-30-2010, 05:48 PM
flashdata not working as expected without redirect() - by El Forum - 02-21-2013, 01:17 PM
flashdata not working as expected without redirect() - by El Forum - 02-21-2013, 02:04 PM
flashdata not working as expected without redirect() - by El Forum - 02-21-2013, 02:17 PM
flashdata not working as expected without redirect() - by El Forum - 02-21-2013, 02:20 PM



Theme © iAndrew 2016 - Forum software by © MyBB