I want to return an alert message to the user if there is an error in updating the data base. I have loaded the doucument parser so I can use $modx call, but haven’t loaded any other classes. The user is logged in type=web and my code is accessed using an AJAX call that expects a Javascript to be returned.
To test the code I used an empty string, $sq, and the following code:
$modx->getSettings();
if($result = $modx->db->query($sq)) {
$msg = $modx->getChunk(’msgSidebarAdProcessed’);
return "alert(’" . $msg . "’);";
} else {
$msg = $modx->getChunk(’errProcessingFailed’);
return "alert(’" . $msg . "’);";
}
The error is being written to the event log, however, I don’t return to this code and the alert isn’t sent back to the user. It looks like the program exits after writing the event log.
I know I could establish a connection outside the document parser, and use mySQL commands, however, I would rather not take that route. I looked at the DBAPI, but can’t see where the errors are being trapped.
I tried using $modx->db->insert(. . .) - but the results were the same.
Any help would be appreciated