views:

881

answers:

2

Hi all,

My goal is to achieve the following; in any environment, Production, Testing or Development, the application can have 2 modes: Production Mode and Debug Mode.

Currently, I have it setup so that the config.ini has this setting. No issues with that.

The problem comes when I want to achieve the following: If the Production Mode is set, I only want to show a custom error page, one with a 404 message if the Controller / Action cannot be found or one with a Generic Error message if a different type of error occurred (exception thrown, connection error, etc). I also need to log the exception where possible to a log/text file. If the Debug Mode is set, all I want to see is the Exception that occurred.

I've tried various methods, but I seem to have hit a dead end. I've tried using the ErrorHandler Plugin but it just show a blank page when an exception occurrs. I've tried using a custom Plugin just to handle 404 errors, doesn't really work because it conflicts with my Authentication Plugin. Tried without the Authentication Plugin, but then it gives issues because of my usage of Modules (just 1 actually, for Admin).

After trying various other things and combinations of them, I can't seem to figure out a way to achieve this.

I would greatly appreciate if anybody can shed some light as to how best to get the desired result.

I also have some assumptions that I would like clarified if I may. They are:

$oFrontController->throwExceptions(false);

Must be set to false in order for the ErrorHandler Plugin to work. Is this correct?

try {
$oFrontController->dispatch();
} catch (Exception $oException) {
...
}

I have the above code to catch Exceptions thrown and log them, but as mentioned above, doesn't seem to do the job (works fine when I'm not using the ErrorHandler though, by setting $oFrontController->throwExceptions(true);).

What's the best way to handle Authentication? I currently have it set up as a Plugin, that sets up the 'resource' based on the module/controller and checks with a ACL class so as whether to give access or not. I've seen some examples where the ACL portion is separate on a controller basis. Would it be more sensible to have the Authentication as a Model that gets called at the initialisation of the controller and checks with it's respective set of permissions if the action should be allowed or not? (I ask this mainly because of the conflict that arose when trying to do error pages with the Authentication to see what alternatives are available)

Thank you for any help that you can give me on this matter. Thank you.

+2  A: 
clyfe
Hi Clyfe,Thanks for the suggestion.Somehow, my setup seems to work now (plain old ErrorHandler plugin). I think perhaps earlier on some sort of conflict may have arisen due to the various methods I was trying out.Going through the Plugin (seems more like a View Helper though), it appears to be quite handy to have while in development. So thanks again for the suggestion.
Jay
A: 

Hi, I know it might be a bit off topic, but I have issues with '$this->getResponse()->setHttpResponseCode(500);' Under win2k8R2 + IIS 7.5 it seems that this will cause a 'standard' non informational IIS 500.0 error page. Anyone with the same issue? Or better, does someone know how to prevent / fix this behaviour?

Thanks. Onno

Onno
hi Onno - this is not just off-topic, this is a whole new question. Why not try asking it as a question, as you will be much more likely to get answers, and you won't be messing up this question with irrelevance. You should delete this "answer" once you've asked it as a proper question. All the best, Ian
Flubba