Welcome Guest, Not a member yet? Register   Sign In
flashdata not cleared
#1

[eluser]shinokada[/eluser]
According to the user manual, it says flashdata are automatically cleared.

However it does not disappear in the following code. It shows "Invalid email. Please try again!" always.

How long flash data keep it data? Is it for 5 min as a default like session data?

Controller

Code:
<?php

class Welcome extends Controller {
  function  __construct(){
    parent::Controller();
    session_start();
    $this->output->enable_profiler(FALSE);
  }
function index(){
    $this->load->helper('form');
      $this->output->cache(30);
    $data['title'] = "Welcome to Claudia's Kids";
    
    $this->load->vars($data);
    $this->load->view('subscribe');
  }
  
function subscribe(){
      if ($this->input->post('email')){
          $this->load->helper('email');
        if (!valid_email($this->input->post('email'))){
            $this->session->set_flashdata('subscribe_msg', 'Invalid email. Please try again!');
            redirect('welcome/index','refresh');
        }
        // $this->MSubscribers->createSubscriber();
        $this->session->set_flashdata('subscribe_msg', 'Thanks for subscribing!');
        redirect('welcome/index','refresh');
      }else{
        $this->session->set_flashdata('subscribe_msg', "You did not fill out the form!");
        redirect('welcome/index','refresh');          
      }
  }
}


Views/subscribe.php

Code:
<?php
if ($this->session->flashdata('subscribe_msg')){
    echo "<div class='message'>";
    echo $this->session->flashdata('subscribe_msg');
    echo "</div>";
}
echo form_open("welcome/subscribe");
echo form_fieldset('Subscribe To Our Newsletter');
$data = array('name'=>'name', 'id' => 'name','size'=>'25');
echo "<p><label for='name'>Name</label><br/>";
echo form_input($data) . "</p>";
$data = array('name'=>'email', 'id' => 'email', 'size'=>'25');
echo "<p><label for='email'>Email</label><br/>";
echo form_input($data) . "</p>";
echo form_submit("submit","subscribe");
echo form_fieldset_close();
echo form_close();
?&gt;
#2

[eluser]iFadey[/eluser]
Flash data is is not cleared after a specific time. I mean there's no time limit for it. It's cleared when you consume it once. On next page request it will be gone.
#3

[eluser]iFadey[/eluser]
This code is from the book Professional CodeIgniter. I think you must compare the above code again with the code provided in the book. Or you can download the complete source code for the book from wrox website. Here's the link:

http://www.wrox.com/WileyCDA/WroxTitle/P...82452.html
#4

[eluser]shinokada[/eluser]
Thanks for your reply, iFadey.

Yes, the code is from the book you mentioned.

Can you think of anything why the flashdata does not disappear?
#5

[eluser]iFadey[/eluser]
Okies. I looked the code in detail. The problem is simple.
You are using caching here.

Code:
$this->output->cache(30);

Actually the flashdata is removed but you have cached the page for 30 min. So it will keep showing you the old page for about 30 min. If you remove caching here, flashdata will be not be displayed again n again.
Caching is very imp for performance but use it with care because sometimes it makes debugging difficult. Again I am not saying that don't use caching. Use caching but with care specially on pages which you think will not change frequently and pages which perform heavy database operations.
#6

[eluser]shinokada[/eluser]
Thanks iFadey.

Appreciate it.
#7

[eluser]iFadey[/eluser]
Your welcome Smile




Theme © iAndrew 2016 - Forum software by © MyBB