|
|||
|
Hello,
I'm beginner .... still reading and testing .... reading and testing ... so I want to ask, what are the best practices in Error and Exception handling in Zend Framework... I mean ... When the input is incorect and want to show an error message or something .. For example ... A blog post is called by its ID argument ... but it's not supplied ... so what is the best way to show an error message like 'the ID argument is missing' ... To handle the error in the controller and make a check if there is error when rendering the view script ... or to redirect to errorController (and if so ... how to pass the message) Thank you Last edited by Dreamer : 08-11-2007 at 07:03 AM. |
|
||||
|
I'm currently working on the error reporting for my companies internal CMS. There is definately a lack of resources for how to handle this critical portion of our apps out there right now. The Zend documentation is nill and tutorials are almost non-existant. Hopefully something will spring up soon. As it is, its a matter of trial and error to find a nice elegant solution. Anyone know of any good ZF Error Handling resources?
|
|
||||
|
You can use the normal try/catch/throw blocks that you would normally use in any other PHP app. Refer to the PHP manual on that: PHP: Exceptions - Manual
You can just do something like this: PHP Code:
So you can use Zend_Exception instead of Exception in the above code. Also be aware that some of the components extend Zend_Exception and may have another Exception object you can use too. Depends on the circumstances. You can also throw your own errors in ZF. Using the missing id for the db record example, you can just do something like this: PHP Code:
|
|
|||
|
Also take a look on Zend_Controller_Plugin_ErrorHandler
Haven't checked myself but it should be useful for wrong controllers/models/action I'm still looking myself... remember to read ApiDoc, got some interesting things off it |
![]() |
| Thread Tools | |
| Display Modes | |
|
|