Skip to content

Instantly share code, notes, and snippets.

@esimonetti esimonetti/errors.php
Last active Jan 30, 2016

Embed
What would you like to do?
PHP driven error messages in Sugar v7 - Works for sidecar and BWC modules
// Assuming that $b is a valid bean instance...
// Assuming we are editing the record...
// On SugarApiException($app_strings[$error_app_label], null, null, 422, 'my_error_code_sample');
// "my_error_code_sample" is displayed on the output as "error"
// $app_strings[$error_app_label] is displayed on the output as "error_message"
$error_app_label = 'LBL_MY_ERROR_MESSAGE';
if(!empty($b->module_name) && isModuleBWC($b->module_name))
{
SugarApplication::appendErrorMessage($app_strings[$error_app_label]);
$urlParameters = array(
'module' => $b->module_name,
'action' => 'EditView'
);
if(!empty($b->id))
{
$urlParameters['record'] = $b->id;
}
$url = 'index.php?' . http_build_query($urlParameters);
SugarApplication::redirect($url);
}
else
{
throw new SugarApiException($app_strings[$error_app_label], null, null, 422, 'my_error_code_sample');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.