How can I debug PHP code in Customer Portal?
Environment:
Customer Portal
Resolution:
If you are experiencing an issue with your Customer Portal pages, one initial thing you may want to do is test in Reference Implementation. This can help you identify if the problem is code related, or product/configuration related. You can find some instructions on how to test in Reference Implementation here:
Answer 7008: Testing Customer Portal problems in Reference Implementation
If you are experiencing a problem with custom code, the single best way to debug the issue is to use the native logMessage() function. You can add logMessage() to your PHP scripts to either record a custom debug message:
logMessage("This is a test message");
Or to write the contents of a variable or caught exception:
catch(exception $e)
{
logMessage($e->getMessage());
}
logMessage() will traverse an array and write it to the log file, but also remember that due to lazy loading in CPHP you may not always see the contents of each array element and you'll need to explicitly write it to the log to see it:
$incident = RNCPHP\Incident::fetch(123456);
logMessage($incident->ReferenceNumber);
Log entries will only be written during Development mode.
Once you've added logging to your PHP script, you can view it by:
1. Going to the Customer Portal Administration Area at https://*yoursite*.custhelp.com/ci/admin
2. Logging in with your admin console credentials
3. Clicking on Logs->Debug Logs in the menu
To prevent unnecessary logging, be sure to comment out or delete any logMessage() calls prior to deploying your PHP code!