পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Tuesday, February 14, 2017

CodeIgniter - Error Handling

Many times, while using application, we come across errors. It is very annoying for the users if the errors are not handled properly. CodeIgniter provides an easy error handling mechanism.
You would like the messages to be displayed, when the application is in developing mode rather than in production mode as the error messages can be solved easily at the developing stage.

The environment of your application can be changed, by changing the line given below from index.php file. This can be set to anything but normally there are three values (development, test, production) used for this purpose.
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
Different environment will require different levels of error reporting. By default, development mode will display errors and testing and live mode will hide them. CodeIgniter provides three functions as shown below to handle errors.
  • show_error() function displays errors in HTML format at the top of the screen.
Syntax show_error($message, $status_code, $heading = 'An Error Was Encountered')
Parameters
  • $message (mixed) − Error message
  • $status_code (int) − HTTP Response status code
  • $heading (string) − Error page heading
Return Type mixed
  • show_404() function displays error if you are trying to access a page which does not exist.
Syntax show_404($page = '', $log_error = TRUE)
Parameters
  • $page (string) – URI string
  • $log_error (bool) – Whether to log the error
Return Type void
  • log_message() function is used to write log messages. This is useful when you want to write custom messages.
Syntax log_message($level, $message, $php_error = FALSE)
Parameters
  • $level (string) − Log level: ‘error’, ‘debug’ or ‘info’
  • $message (string) − Message to log
  • $php_error (bool) − Whether we’re logging a native PHP error message
Return Type void
Logging can be enabled in application/config/config.php file. Given below is the screenshot of config.php file, where you can set threshold value.
/*
|--------------------------------------------------------------------------------
|   Error Logging Threshold
|--------------------------------------------------------------------------------
| You can enable error logging by setting a threshold over zero. The 
| threshold determines what gets logged. Threshold options are:
|
|   0 = Disable logging, Error logging TURNED OFF
|   1 = Error Message (including PHP errors)
|   2 = Debug Message
|   3 = Informational Messages
|   4 = All Messages
|
| You can also pass an array with threshold levels to show individual error types
|
|   array(2) = Debug Message, without Error Messages
| For a live site you'll usually only enable Errors (1) to be logged otherwise 
| your log files will fill up very fast.
|
*/
$config['log_threshold'] = 0;
You can find the log messages in application/log/. Make sure that this directory is writable before you enable log files.
Various templates for error messages can be found in application/views/errors/cli or application/views/errors/html.

No comments:

Post a Comment