Skip to content
  • Home
  • Server-Side
    • php
    • Node.js
    • ASP.NET
    • Magento
    • Codeigniter
    • Laravel
    • Yii
    • CRUD
      • CRUD Database Application
      • CRUD operation in Client side
      • CRUD operation with server side
  • JavaScript
    • AngularJS
    • Ajax
    • VueJs
    • jQuery
    • ReactJS
    • JavaScript
    • SEO
  • Programming
    • Android
    • C programming
    • CSS
    • Mysql
    • Mysqli
  • Technology
    • Software
      • webinar software
      • webinar conferencing software
      • soundproof
    • Adsense
      • Google
      • Earn Money
      • Google Adsense
        • Adsense fraud
        • Adsense Secrets
        • Adsense software
        • Adwords advice
        • Adwords strategy
        • Google adwords help
        • How to get google ads
    • Tips and Tricks
    • Interview
    • Insurance
    • Religious
    • Entertainment
      • Bollywood
      • tamilrockers
      • Hollywood
  • Health Care
    • LifeStyle
    • Women
    • Fashion
    • Top10
    • Jobs
  • Tools
    • Screen Resolution
    • WORD COUNTER
    • Online Text Case Converter
    • what is my screen resolution?
  • Guest Post
    • 4cgandhi
    • IFSC Code

Set flashdata(set_flashdata) in codeigniter Example

October 25, 2020 by Pakainfo

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 Flashdata – how to use Flashdata in codeigniter

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

set_flashdata codeigniter
set_flashdata codeigniter

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).
Also Read: Session Management in CodeIgniter with PHP
To check a current thing as “flashdata”:

Read Also:  codeigniter get session data in controller

// 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'));
[/php
 
<h2>To include codeigniter Flashdata:</h2>
 
 
// 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.

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:

Read Also:  Vuejs Dynamic Dropdown Select Menu using json

// set flashdata
$this->session->flashdata('result');

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

Also Read: Codeigniter Session set and Retrieve multidimensional array

// set flashdata
$this->session->flashdata();

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

<?php
class Example_FlashData_Controller extends CI_Controller
{
 
public function index()
{
// set Load session library
$this->load->library('session');
 
// set redirect to home page
$this->load->view('flashdata_home');
}
 
public function add_flashData()
{
// set Load session library
$this->load->library('session');
$this->load->helper('url');
 
// add hear flash data
$this->session->set_flashdata('item','set-item-value');
 
// set redirect to home page
redirect('flashdata');
}
}
?>

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

Read Also:  Laravel Group By Clause/Statement

<!DOCTYPE html>
<html lang = "en">
 
<head>
<meta charset = "utf-8">
<title>CodeIgniter Flashdata Example - pakainfo</title>
</head>
 
<body>
CodeIgniter Flashdata Example <br/>
<h2><?php echo $this->session->flashdata('item'); ?></h2>
<a href = 'flashdata/add'>Click Here</a> to add for CodeIgniter Flashdata.
</body>
 
</html>

Also Read: CodeIgniter Simple User Registration and Login System
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 pakainfo with the URL of your website.
http://pakainfo/index.php/flashdata

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.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Laravel Redirect Route with get query string parameters
  2. Read Also:  Full form of Networking Parts
  3. Read Also:  php search engine script for mysql database
  4. Read Also:  Set Cookies Get Cookies Delete Cookies with PHP
  5. Read Also:  Vue js Multiple Tag Input with Dynamic Autocomplete
  6. Read Also:  PHP Handle Multiple Checkbox Array
  7. Read Also:  laravel flash message Notification in Blade template
  8. Read Also:  how to display success message in codeigniter?
  9. Read Also:  Session Management in CodeIgniter with PHP
  10. Read Also:  PHP Laravel Check if Array is empty
Categories Codeigniter, php, Programming Tags codeigniter 3 flash message, codeigniter flash message bootstrap, codeigniter session not working, how to display success message in codeigniter, session in codeigniter for login, set session in codeigniter, set_flashdata codeigniter not working, unset flashdata in codeigniter
Post navigation
PHP Pagination demo – Pagination in PHP with example script
Java super Keyword Examples with Demo

Categories

Ajax (414) AngularJS (357) ASP.NET (61) Bollywood (34) Business (16) Codeigniter (141) C programming (13) CSS (62) Earn Money (50) Education (30) Entertainment (40) Events (14) Google Adsense (58) Government (13) Highcharts (77) Hollywood (33) Interview (18) JavaScript (850) Jobs (25) jQuery (927) Laravel (998) LifeStyle (30) linux (18) Magento (13) Mysql (862) Mysqli (770) Node.js (34) php (1668) Programming (2171) Python (44) ReactJS (33) SEO (22) Software (16) Software (38) tamilrockers (29) Tech (15) Technology (2179) Tips and Tricks (75) Tools (27) Top10 (109) VueJs (249) Web Technology (28) wordpress (135) World (22) Yii (14)
© 2021 Pakainfo • Developed By Pakainfo.com