Skip to content

RationalEar/codeigniter-error-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

codeigniter-error-manager

Codeigniter Library for managing error messages generated by system (not PHP errors)

Author: Michael M Chiwere

Installation

  1. Copy and merge contents of application folder into your codeigniter application folder
  2. Open the Error.php library to setup some default variables for your error messages
  3. Open autoload.php in application/config/ folder and add the 'error' in the libraries array. Make sure the 'session' library is also auto loaded and must be loaded before the 'error' library.
  4. Also add 'error' and 'url' to the helpers array in the autoload.php file
  5. If you are using bootstrap 3 and above, then thats all.
  6. If you are not using bootstrap, you may need to setup your own css classes to format the error messages

USAGE

  1. Set error messages by using the sem() method. see examples below
  2. display error messages by calling the gem() method

EXAMPLE 1. To set a new error message, call the helper function sem().

1a. suppose an error has occured e.g during login, username/password are incorrect, set error message as follows:
	method A: sem('Login Failed, please check your username/password');
	method B: sem('Login Failed, please check your username/password', TRUE);
	method C: sem( [ 'error'=>TRUE, 'error_msg'=>'Login Failed, please check your username/password' ] );
	
1b. suppose an operation was successful, e.g account created successfully. Set success message as follows:
	method A: sem('Thank you for registering. You account has been created successfully', FALSE);
	method B: sem( ['error'=>FALSE, 'error_msg'=>'Thank you for registering. You account has been created successfully'] );

1c. suppose you also want the error message to be written to the log file. Note that you can send the log flag as either 'ERROR' or 'DEBUG'
	method A: sem('Login Failed, please check your username/password', TRUE, 'ERROR');
	method B: sem( [ 'error'=>TRUE, 'error_msg'=>'Login Failed, please check your username/password' ], TRUE, 'ERROR' );

EXAMPLE 2. To get array of error messages, call the helper function gem().

2a. gem() function will return an array containing the error messages and the error flags (e.g success, error, info).
	// php code to loop through array of error messages
	$error = gem();
	<?php foreach( $error as $e ):?>
		<div class="<?php echo $e['f'];?>">
			<?php echo $e['msg'];?>
		</div>
	<?php endforeach;?>

EXAMPLE 3. print error messages using helper function show_errors().

3a. show_errors() function will print the error messages at the exact place you call it
3b. show_errors(TRUE) function will also display form validation errors if you are using the codeigniter form_validation library.
3c. show_errors( FALSE, TRUE, 'custom_message_field' ) will also fetch a string from flashdata field with the name you specify in the third parameter.

Need help, contact me on michaelmartinc@gmail.com

THANK YOU!

About

Codeigniter Library for managing system errors

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages