Background: I am writing a little app to help us here at Railo with some of our contacts, nothing over the top or anything and wanted to take Sean Corfield's FW/1 for a spin.
As I am developing, I went the most direct route, I just did some queries in the service layer so my code looks like:
<cffunction name="list" output="false"> <cfset var clients = 0> <cfquery name="clients" datasource="#variables.dsn#"> SELECT * FROM contact; </cfquery> <cfreturn clients> </cffunction> <cffunction name="view" output="false"> <cfargument name="clientid"> <cfset var qclient = 0> <cfquery name="qclient" datasource="#variables.dsn#"> SELECT * FROM contact WHERE id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.clientid#">; </cfquery> <cfreturn qclient> </cffunction>
OK, nothing world shattering, so I wanted to start using the ORM features of Railo (join the pre-release group to test them out!). I changed my code to look like:
<cffunction name="list" output="false">
<cfset var clients = 0>
<cfquery name="clients" dbtype="orm">
FROM contact
</cfquery>
<cfreturn clients>
</cffunction>
<cffunction name="view" output="false">
<cfargument name="id">
<cfreturn entityLoad("contact",arguments.id,true)>
</cffunction>
I then defined my "contact" (I can show the code but it's hardly rocket science) and then when I reloaded I got the error:
Component [contact] has no acessible Member with name [ID]
Of course! My view code looks like:
<input type="hidden" name="id" value="#rc.data.id#">
I could change all my calls to fields to
<input type="hidden" name="id" value="#rc.data.getid()#">
but why bother? I just went to the Railo Admin -> Archives & Resources: Component -> Magic Functions and enabled them, now all my view code works just as expected and I didn't have to change my view code.








4 responses so far ↓
1 Tony Garcia // Aug 6, 2010 at 5:59 PM
check out:
http://eli.thegreenplace.net/2009/02/06/getters-and-setters-in-python/
2 Laura // Aug 6, 2010 at 8:59 PM
3 John Farrar // Aug 6, 2010 at 11:38 PM
4 Mark Drew // Aug 9, 2010 at 11:04 AM
Leave a Comment