News Feed
Jobs Feed
Sections




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

Jani Hartikainen's Blog:
Using models as criteria objects for querying the database
January 26, 2009 @ 08:47:28

This new post from Jani Hartikainen talks about models and how you can use models together with others (in this case, for searching your application's data).

If you have written a model layer which separates database access from the rest of the code, you probably know that you may end up with lots of methods like findByName, findByTitle or such, for cases where you want to find records based on specific criterias. [...] You could also use your model objects as search 'œcriterias' - A bit similar to how Propel handles criterias, but not as nearly as complex.

His simple example (making a user object, assigning a name to it and then passing it to a gateway to search on that name) illustrates one major benefit of using model objects in others - prevalidation. In this case, checking to see if the name passed in is even valid before continuing.

He also provides a bit more complex example - the contents of that user gateway model that can check to be sure that the user even exists.

0 comments voice your opinion now!
model criteria object query database validate


blog comments powered by Disqus

Similar Posts

Felix Geisendorfer's Blog: Migrating from WordPress to CakePHP

Greg Beaver's Blog: Synchronize live and development sites using the PEAR Installer

Zend Developer Zone: Generating and Validating Web Forms With PEAR HTML_QuickForm (part 2)

ZendCasts.com: Logging with Timestamps and Doctrine Event Listeners

Jani Hartikainen's Blog: Unit testing 4: Mock objects and testing code which uses the database


Community Events











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


hack application overview install introduction framework symfony2 language composer code facebook component hhvm opinion podcast release security package example unittest

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