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.

21 Comments

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

  2. Do you have a spam issue on this site; I also
    am a blogger, and I was wanting to know your situation; many of us have developed
    some nice methods and we are looking to trade solutions with
    others, why not shoot me an email if interested.

  3. Hello there, I found your blog via Google whilst looking for a related subject,
    your web site got here up, it appears to be like great.
    I’ve bookmarked it in my google bookmarks.
    Hello there, just became aware of your blog thru Google, and
    found that it is truly informative. I am going to watch out for brussels.
    I’ll be grateful in the event you continue this in future.
    Lots of other people might be benefited from your writing.
    Cheers!

  4. Unquestionably imagine that which you stated. Your favorite justification seemed to be
    on the net the easiest factor to take into accout of. I say to you, I certainly
    get annoyed at the same time as other people consider concerns that they plainly don’t recognise about.
    You controlled to hit the nail upon the highest and also
    outlined out the whole thing with no need side-effects , other people could take a signal.
    Will probably be back to get more. Thanks

  5. Its like you rwad my thoughts! You appear to grasp sso muc about this, such as
    you wrote the guide in it or something. I think that you can do with some percent
    to power the message home a little bit, however instead of that, that is excellent blog.

    A great read. I’ll cewrtainly be back.

  6. Log into: https://bit.ly/exercisefitnessandhealth

    Free to all who need it – and everyone does need it. My Blog explains all you need to know about exercise – what it involves, how it is measured, how much you should take, the effect on health and lifespan and the great improvement in quality of life which regular physical activity brings

    Sign up and I will send you a weekly update

Leave a Reply

Your email address will not be published.