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

Matthew Weir O'Phinney's Blog:
Search APIs
Jun 06, 2005 @ 11:18:07

Matthew Weir O'Phinney has a new posting over on his blog today with a look at how to create or alter database search functionality in some APIs for work - Search APIs.

In doing this work, I discovered some techniques that make this process much easier. In line with The Pragmatic Programmer, I found myself exploring the DRY principle (Don't Repeat Yourself), and looking into code generation (this time, SQL) -- basically to exploit my inherent laziness and to make my job easier.

I thought I'd share some of the principles I've discovered for myself as I haven't read much information on the subject. Some of this may be rudimentary for some readers or those who work with more advanced abstraction layers.

He follows this method: Store individual criteria and joins in a class array, Pass search criteria as an associative array, Set up default criteria, Store criteria and values in arrays during processing, Keep track of JOINs, Allow retrieval of record counts only, and finally, Putting it together. He gives all the code that he worked up, and includes a few final thoughts as to how this code could even be made more flexible, and the fact that what he's written is a part of a Model from a MVC Framework (gaining more and more popularity in the community...more info here).

tagged:

Link:


Trending Topics: