CodeIgniter send and retrieve data using flash messages ?

I am gonna teach you about CodeIgniter flash messages. CI’s flash sessions functionality  let us to use the data for the next server request.Unlike normal sessions flash data will be destroyed permanently after next request, Therefore these can be very useful, and are typically used for showing informational or status messages for example we can use for showing success messages , error messages.. etc.

Note: Flash variables are prefaced with “flash_” so avoid this prefix in your own session names.

How to use

To use flash session in CI, we must configure session key in application/config/config.php file and we must load session library by using auto load mechanism or we can load it in controller or in action.

To add flash data :

To read or get the data from flash data:

If you find that you need to preserve a flashdata variable through an additional request, you can do so using the keep_flashdata() function.

 

Show me example:

For example if user redirects to index action(page) after adding, updating and deleting a record we gonna show message to the user.

Open your controller just add the line before redirect .

you can check and set failure messages also something like

now open your view file (Example : test_view.php). Write code someting like shown below

Hey , we finally knew how to use flash data in CI application. Happy coding …if you get any issues and if i missed anything here let me know via comments i will update the post.Thanks.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 vote
Article Rating
Subscribe
Notify of
guest
6 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
freddy
freddy
6 years ago

Your Website is really cool brother ?

Divyesh Bharadva
Divyesh Bharadva
5 years ago

Hi Arjun,

I m getting an error while use your code in my application.

The error that I face is : Fatal error: Can’t use method return value in write context in /home/myapp/public_html/application/views/special/test.php on line 66

At line 66, the code is : if(isset($this->session->flashdata(‘item’)))

Please let me know how to solve this error.

Looking forward to your reply.

arjun
5 years ago

remove isset()

Ucup Timposu
2 years ago

You fix my problem,,,
thanks for u solution

Arlene Westcott
Arlene Westcott
1 year ago

Hi,

I am a passionate reader and reaching you in context to something like this. I would like to do a contribution to your website by providing a guest post.

The guest post would surely be based on a great topic aligned with your reader’s interests. The content would be of high quality and will be plagiarism-free. However, in return would need a favor of backlink within the main body of the article.

Kindly let me know if I can interest you with some great topic ideas?

Looking forward.

Sincerely,

Arlene Westcott

yash shah
yash shah
9 months ago

set_flashdata works very well in my local.computer but while i upload in server
it didn’t work properly , sometimes works fine

DMCA.com Protection Status
6
0
Would love your thoughts, please comment.x
()
x