Skip to content

A small snippet for setting and alerting users for error, success, warning messages

License

Notifications You must be signed in to change notification settings

chivins-softwares/Codeigniter-Bootstrap-alert-message

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Codeigniter Bootstrap alert message

You need to check on the controller and the view folder to see how to use this small code. It is just a small step which will not even take time to understand its usage.

First load library
First we will need to load our library either autoload through application => config => autoload.php look for

$autoload[libraries'] 

then add this

$autoload['libraries'] = array('alert'); 

or we just load it through our controller, model, libraries as

$this->load->library('alert'); 

This snippet came with two main method for client or developer usage

  1. set($msg, $alert_type, $alert_identification_key)
    Description: This method is used to set the alert message. Mind you, this snippet uses three parameters
    $msg => The message you want to pass to the user
    $alert_type => The alert type you are trying to trigger e.g error, success, info, and warning
    $alert_identification_key => the key to use identify the particular message you want to display to the user
    usage:
$this->alert->set('Hello Chivins fans. You have successful view our snippet', 'success', 'snippet_alert');


  1. get($alert_identification_key)
    Description: This method is used to return the alert message base on its identification key. Mind you, this snippet uses one parameter
    $alert_identification_key => the key to use identify the particular message you want to return to the user
    usage:
echo $this->alert->get('snippet_alert'); // Output: Hello Chivins fans. You have successful view our snippet

You can go ahead to try this to make your alert work in your project

Try this

  class Login extends CI_Controller {
	  public function __construct()
		{
			parent::__construct();
			
			$this->load->library('alert');
		}
	
		public function index()
		{
			if (!$this->chivins_users->isLogin()) {
				// Set the alert error message if the user is not logged in
				$this->alert->set('You are not logged in. Login to access this page', 'error', 'login_msg');
			}
			else{
				$this->alert->set('Welcome you have successfully logged in to your account', 'success', 'login_msg');
			}
		}
	
	}

then on the view part try this

echo $this->alert->get('login_msg');

That is all. There is no big deal to it More update is coming

Releases

No releases published

Packages

No packages published

Languages