News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Felix Geisendorfer's Blog:
Making error handling for Modelsave more beautiful in CakePHP
February 06, 2007 @ 10:05:00

In a new post to his blog today, Felix Geisendorfer shares a method to make error handling in the CakePHP model functionality a bit more "beautiful".

Now I've written actions like the one above in the past as well. It's just that I've not had many MySql errors since I've switched to CakePHP. The Model class usually handles all the DB operations flawlessly and it's probably been over a year that I've written a custom MySql statement in my code somewhere. However, even CakePHP or, what's more likely, the database can fail or deny operations.

He shows some code snippets of what he sees as less beautiful versions of database insertion code, methods that either don't check the response/errors or make a messy job of it. His solution works by returning the result into a switch statement to check the results and handling it there (versus a series of ifs). There's a class you'll need to make it work (Common), but he shows how to use it and creates a simple "add" example with it and a new Controller to handle the request.

0 comments voice your opinion now!
cakephp save model controller beautiful cakephp save model controller beautiful


blog comments powered by Disqus

Similar Posts

Karsten Deubert's Blog: Zend_MVC, Controller Plugins and Annotations

Federico Cargnelutti's Blog: Testing Zend Framework Action Controllers With Mocks

Felix Geisendorfer's Blog: Validating the cleaned output of HtmlHelper::dateTimeOptionTag()

IBM developerWorks: PHP frameworks, Part 1: Getting started with three popular frameworks

Felix Geisendorfer's Blog: Model::save() now returns an array!


Community Events

Don't see your event here?
Let us know!


api voicesoftheelephpant wordpress laravel5 conference extension opinion psr7 library language development introduction release community podcast unittest series framework laravel interview

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework