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.

READ :  Best Online Masters Degrees in Norway

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).

 flashdata in codeigniter
flashdata in codeigniter

To check a current thing as “flashdata”:

// set codeigniter Flashdata
$this->session->mark_as_flash('result');

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'));

To include codeigniter Flashdata:

// set session value
$_SESSION['result'] = 'result';
// set mark_as_flash value
$this->session->mark_as_flash('result');

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
$_SESSION['result']

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

READ :  C# swap two numbers without third variable

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
$this->session->flashdata('result');

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

// set flashdata
$this->session->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
$this->session->keep_flashdata('result');
// 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.


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








CodeIgniter Flashdata Example

Click Here 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 infinityknow with the URL of your website.

READ :  How to Find The Total Number of Products in WP REST API v3?

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.

Leave a Reply

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