Is it customary to have SQL in CFWheels Controllers?

July 18, 2012 by Mike Henke    2 Comments
Posted under: CFWheels

I had this question emailed to me "Is it customary to have SQL in CFWheels Controllers?"

No. If it is very complex sql or a stored proc, I would create a cfc representing it in the models folder like this:


<cfcomponent extends="Model">
<cffunction name="myfirststoredproc">
<cfstoredproc procedure="spListRegions">
<cfprocresult name="qRegions">
<cfreturn spListRegions>

then in the controller call and pass in the values:

<cfset smellyCode= model("myStoredProc").myfirststoredproc(1)>

Once using wheels, you'll get a smell testing going. Complex SQL and stored procs will seem out of place in the actual controller since the Controller should only gather and process.

Hopefully this helps :-)