This is the documentation for concrete5 version 5.6 and earlier. View Current Documentation

Exceptions and PHP Errors in concrete5

Error Levels for Production and Development

Your site's error level may be set in Dashboard > Settings > Debug.

Development

All PHP errors besides E_NOTICE should be displayed within the page. All exceptions will be displayed.

Production

PHP errors will not be displayed in the browser. Exceptions will be displayed with a generic error message.

Exceptions

All exceptions in concrete5 are rendered by View::renderError(). If a theme contains a file named "error.php," it will be used to render these error screens.

Exceptions will also be logged in the Dashboard > Reports > Logs section, if "Enable Exceptions Log" is checked in Dashboard > Settings > Debug.

Handling Block and Single Page Application Errors Using the ValidationErrorHelper Object

The ValidationError Helper is a simple object that you can add errors to, and then later check against. Use this object in your control statements to gather up all errors associated with a given process, and later iterate through them or display them to the end user.

Loading the Helper

$val = Loader::helper('validation/error');

Example of Usage

$val = Loader::helper('validation/error'); 	if ($_POST['name'] == '') { 		$val->add('You must specify a name.'); 	} 	 	if ($val->has()) { 		print t('There were errors with your request:'); 		$val->output(); 	} 

Methods

$val->add($e)

Adds an error to the helper's internal error array. $e may be one of the following

  • A PHP5 Exception
  • A simple string
  • Another instance of the ValidationErrorHelper object

$r = $val->getList();

Get the list of errors associated with the helper. Returns an array of strings.

$r = $val->has();

Returns true if the error helper object has errors within it, false if not.

$val->output();

Prints out an HTML list containing all errors. This is an unordered list with a CSS class of "ccm-error."

Outputting Errors in the Dashboard

It's easy to use the ValidationErrorHelper object for error handling in the concrete5 dashboard. The internal dashboard theme will check to see if a variable of the name $error exists, and if it's an instance of the ValidationErrorHelper, the list will be output. Simply set the "error" variable using Controller::set() function at the end of your controller function.

Example

	public function save_dashboard_form() { 		$val = Loader::helper('validation/error'); 		if ($_POST['name'] == '') { 			$val->add('You must specify a name.'); 		} 		 		$this->set('error', $val); 	}

The $error variable will only be output it actually has errors associated with it.

Loading Conversation