IF Session data exists, is displayed

So, I am trying to infer the value of a session variable into a view (only if it exists). But I can’t make it work. There is no mistake. Nothing. What am I missing? Thought I had fallen now - I don’t think ...

In the controller ... FYI, the data is assigned to the view (i.e. $this -> load -> view('view', $data);

 $data['campaign_name'] = $this -> session -> userdata('campaign_name'); 

Here is my php snippet in the view I'm trying to output. In short, if the session exists, print it. If not, do nothing.

 <input type="text" name="campaign_name" class="wizardInput nameField" value="<? if (isset($campaign_name)) ;?> "> 

Is anyone

EDIT Alright, I should have mentioned that I'm trying to infer a session value into a FORM value. Changed view code above. The form gives, as if the value is, and even sends the value. However, it does not appear in the text input ...

+4
source share
1 answer

you can easily do this in your view:

 if($this->session->userdata('campaign_name')){ // do somenthing cause it exist } 

then if you want to make the session data as an input value, do the following:

 <input type="text" name="campaign_name" class="wizardInput nameField" value="<?php echo $this->session->userdata('campaign_name') ?>"> 

you do not need to control whether existing user session data exists , if it does not exist, it does not print anything, the reason userdata() returns false !

Then you do not need to transfer session data through the $data[] array , call the session data from anywhere (model / controllers / views / hooks / libraries / helpers, etc.)

+8
source

Source: https://habr.com/ru/post/1447293/


All Articles