What happens if an invalid UserID is passed in, and as such the query
returns no data? (I bet passing in a '0' would cause this). Do you
want to throw an error, or return an empty UserVO?
The code looks solid enough for me, though.
Following best practices query, some may suggest you should separate
out the getUser query into a Data Access Object. However, given your
current implementation I see no reason your you can't re-factor to that
at some future point if needed.
Simon Bailey wrote:
> ColdFusion, I use it, luv it, but by far am no means as dynamic in my
> knowledge of it as I would like! This said I would like to ask the
> CF pro's on this list if they could cast their eyes over this method
> and pass judgement, is it adhering to practices you woul use and
> could it be written better? Any input would be most GREATLY appreciate!
>
> The method essentially is called from Flex which passes a user id to
> retrieve that specific user details, it then returns the user details
> as a Value Object UserVO back to Flex!
>
> <cffunction name="getUserByID" returntype="UserVO" access="package">
> <cfargument name="user_id" type="Numeric" required="true"/>
> <cfset var user= createObject("component", "UserVO")/>
> <cfset var getuser=""/>
> <cfquery name="getuser" datasource="#dsn#" username="#un#"
> password="#pw#">
> SELECT user_id, userpassword, user_name
> FROM users
> WHERE user_id = <cfqueryparam CFSQLType="cf_sql_int"
> value="#arguments.user_id#">
> </cfquery>
> <cfset user.user_id = getuser.user_id/>
> <cfset user.userpassword = getuser.userpassword/>
> <cfset user.user_name = getuser.user_name/>
> <cfreturn user/>
> </cffunction>
>
> Cheers
>
> Simon
>
> Blog: nutrixinteractive.com/blog/
>
>
>
>
>
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;160198600;22374440;w
Archive: http://www.houseoffusion.com/groups/Flex/message.cfm/messageid:4913
Subscription: http://www.houseoffusion.com/groups/Flex/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.37