codeigniter Flashdata – how to use Flashdata in codeigniter

codeigniter Flashdata – how to use Flashdata in codeigniter

In this post we will hsow you how to use codeigniter Flashdata, While building web application, we have to store a few information for just a single time and after that we need to evacuate that information. For instance, to show some mistake message or data message. In PHP, we need to do it physically yet CodeIgniter has made this employment straightforward for us. In CodeIgniter, codeigniter Flashdata might be accessible until the following solicitation, and it will get erased naturally.

CodeIgniter underpins “flashdata”, or session information that might be accessible for the following solicitation, and is then naturally cleared.

This can be exceptionally helpful, particularly for one-time instructive, mistake or status messages (for instance: “result 2 erased”).

It ought to be noticed that flashdata factors are consistent session vars, just set apart particularly under the '__ci_vars' key (kindly don’t touch that one, you’ve been cautioned).

To check a current thing as “flashdata”:

// set codeigniter Flashdata

If you need to check various things as codeigniter Flashdata, just pass the keys as an array:

// set session data
$this->session->mark_as_flash(array('result1', 'result2'));

<h2>To include codeigniter Flashdata:</h2>

// set session value
$_SESSION['result'] = 'result';
// set mark_as_flash value

Or on the other hand, utilizing the set_flashdata() method:

// set result and value
$this->session->set_flashdata('result', 'set_value');

You can likewise pass an exhibit to set_flashdata(), in an indistinguishable way from set_userdata().

Reading codeigniter Flashdata factors is the same as perusing standard session information through $_SESSION:

// set SESSION

Imperative :: The userdata() technique won’t return flashdata things.

In any case, on the off chance that you need to make certain that you’re perusing “flashdata” (and no other kind), you can likewise utilize the flashdata() technique:

// set flashdata

Or, on the other hand to get a cluster with all codeigniter Flashdata, basically preclude the key parameter:

// set flashdata

Note :: The flashdata() strategy returns NULL if the thing can’t be found. In the event that you find that you have to safeguard a codeigniter Flashdata variable through an extra demand, you can do as such utilizing the keep_flashdata() strategy. You can either pass a solitary thing or a variety of codeigniter Flashdata things to keep.

// keep lashdata single value
// keep lashdata array
$this->session->keep_flashdata(array('result1', 'result2', 'result3'));

Example for codeigniter flashdata

Make a class called FlashData_Controller.php and spare it at application/controller/Example_FlashData_Controller.php.

class Example_FlashData_Controller extends CI_Controller

public function index()
// set Load session library

// set redirect to home page

public function add_flashData()
// set Load session library

// add hear flash data

// set redirect to home page

Make a view document called flashdata_home.php and spare it in application/sees/flashdata_home.php

<!DOCTYPE html>
<html lang = "en">

<meta charset = "utf-8">
<title>CodeIgniter Flashdata Example - onlinecode</title>

CodeIgniter Flashdata Example <br/>
<h2><?php echo $this->session->flashdata('item'); ?></h2>
<a href = 'flashdata/add'>Click Here</a> to add for CodeIgniter Flashdata.


Roll out the improvements in the routes.php document in application/config/routes.php and include the accompanying line toward the finish of the record.

// set flashdata route
$route['flashdata'] = 'Example_FlashData_Controller';
$route['flashdata/add'] = 'Example_FlashData_Controller/add_flashData';

Execute the above case by going to the accompanying connection. Supplant the onlinecode with the URL of your website.

Tap on “Click Here” connection and you will see a screen as demonstrated as follows. Here, in this screen you will see an estimation of glimmer information variable. Invigorate the page again and you will see a screen like above and streak information variable will be expelled consequently.

You also like Remove index.php from url in codeigniter and CodeIgniter – Image and File Upload and and CodeIgniter UPDATE Query and Codeigniter Delete Query

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  59  =  69

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US