How to show error message in codeigniter?

by raven_corwin , in category: PHP Frameworks , 7 months ago

How to show error message in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by addison , 7 months ago

@raven_corwin 

In CodeIgniter, you can show error messages by using the set_flashdata() method in the controller and then accessing the flashdata in the view to display the error message. Here's an example of how you can show an error message in CodeIgniter:

  1. In the controller, set the error message using set_flashdata() method:
1
$this->session->set_flashdata('error', 'An error occurred. Please try again.');


  1. In the view, check if the flashdata exists and display the error message:
1
2
3
4
5
<?php if ($this->session->flashdata('error')): ?>
    <div class="alert alert-danger">
        <?php echo $this->session->flashdata('error'); ?>
    </div>
<?php endif; ?>


By following these steps, you can easily display error messages in CodeIgniter.