tags:

views:

64

answers:

1

I have my own AppCotroller and using the beforeRender method to make changes to $this->viewPath based on the desired output format.

Is there a way I can check if Cake is currently outputting an error message? If I change the viewPath and then it's displaying an error (like can't load model, etc) it will error on the error :)

A: 

By the time Cake is displaying the error it should already be too late to do something about it. Not quite sure why you'd get an error about missing models when you change the viewPath, I hope that was just an example.

You might have some luck overriding or extending the ErrorHandler to intercept errors, but I wouldn't recommend doing that. Errors don't exist to be hidden, they're there to tell you something.

Creating a custom View might be a good idea depending on what you want to do (see the MediaView as an example of an alternative view).

The best thing to do though should be to avoid triggering errors by only allowing certain, predefined views to be set or making sure that a certain view file exists before trying to invoke it.

deceze
Problem is, when Cake goes to display the error about a missing model the app controller is adjusting the viewPath. Because of the path change it will then error because it can't find the view to display the model error (and it will not display the model error, it will display the problem finding view error)
Louis W