Welcome Guest, Not a member yet? Register   Sign In
How to check if flashdata session is empty or not yet created in View?
#1

[eluser]joneslee[/eluser]
Hi there,
I am writing a simple login page in which error text will be stored as flashdata. I created a visible div in the presentation page to show that error. What I try to achieve is to check if there is no flashdata then the DIV will be set to style='display:none' else set it to 'visible'. I use the following code:

View:
Code:
if(empty($this->session->flashdata('msg')
   $display_string = 'none';
else
   $display_string = 'visible';

<div id="loginStatus" style="display: &lt;?= $display ?&gt;">
  <code>
    &lt;?=$this->session->flashdata('msg');?&gt;
  </code>
</div>

I got an error said that cannot return value in a write context page..

Here is my controller:

Controller:
Code:
if ($this->form_validation->run() == false) {
            $this->session->set_flashdata('msg', $this->form_validation->error_string('<span>', '</span><br/>'));
            $this->session->set_flashdata($_POST);
            redirect('home', 'location');
}

Can someone show me how could I check whether the flashdata is yet created or empty in View layer?
#2

[eluser]elvix[/eluser]
try $this->session->flashdata('msg') != ''
#3

[eluser]joneslee[/eluser]
Holy moly thanks, it works, i am happi Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB