I'd replace the direct property assignments:
<cfset user.user_id = getuser.user_id/>
<cfset user.userpassword = getuser.userpassword/>
<cfset user.user_name = getuser.user_name/>
with setters:
<cfset user.SetUserID(getuser.user_id) />
<cfset user.SetUserPassword(getuser.userpassword) />
<cfset user.SetUserName(getuser.user_name) />
This allows for logic (e.g. validation) to be part of the process.
I'd also be looking at injecting the user object into the component
via ColdSpring.
On Feb 13, 2008 12:36 AM, Simon Bailey <[EMAIL PROTECTED]> 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:4923
Subscription: http://www.houseoffusion.com/groups/Flex/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.37