In methods of controllers, there are usually many checks for “doing the right thing”.
For instance, I check if user is accessing the right data.
However, I’m wondering what is the best way to return or exit from these methods when errors do occur. I’ve been using just simple return statement, but is there anything that’s more CakePHP-like and follow the framework’s design? or is simple return/exit statement good enough?
This really depends on what you want to do.
If you are processing a form post, and the data validation failed, a simple return is enough.
If the validation has passed, a redirect is more appropriate (to prevent double posting the data with potentially terrible consequences).
In case of a really fatal error, potentially not even caused by your own code (unlikely, right?:)), cake gives you a few options of handling those errors, via AppController::appError() or the whole class called AppError.
See more info here:
http://book.cakephp.org/view/154/Error-Handling