2009-03-06 8 views
9

Buduję listę najlepszych praktyk CFC do udostępnienia.Zbiór najlepszych/zalecanych metod CFC ColdFusion?

Istnieje wiele artykułów tam, ale pomyślałem, że może to być zgrabne, aby uzyskać wszystkie sztuczki i wskazówki tutaj w jednym miejscu, które zostały nabyte dzięki doświadczeniu.

Dodam tu kilka linków, ale myślę, że najlepszą rzeczą byłoby nie długich artykułów, które można znaleźć w Google.

CFC Best Practices

Macromedia CFC Best Practices

Aktualizacja: Zostało wykonane w wiki społeczności

+0

1) Zawsze upewnij wyniki są powtarzalne przed zawiadomić prasę ... – Shog9

+0

Wygląda to jak pytanie typu wiki społecznościowe? Tak czy inaczej, chciałbym poprosić o poprawioną nazwę, ponieważ nie zgadzam się na użycie słowa "najlepiej", gdy dokładniejsze słowo jest zazwyczaj "zalecane" lub "modne", ponieważ to, co jest "najlepsze", prawie zawsze jest kwestią kontekst. –

+0

Peter, gotowe i gotowe! –

Odpowiedz

0

Przed użyciem ColdBox Framework nie widzę żadnych wiadomości na temat korzystania Momentos uchwycić właściwości w tym momencie; jednak teraz wszystkie moje komponenty bean mają metodę getMomento() i setMomento(). Zachęcam to jako najlepszą praktykę dla każdego, kto potrzebuje przekazać informacje z fasoli do innego obiektu DAO.

W moich testach, uzyskanie chwili jest znacznie szybsze niż podanie fasoli i uzyskanie jej właściwości. Oto przykład:

<cfcomponent name="userBean" output="true" hint="The account bean holds getter/setter information for a user's account."> 

<cfproperty name="idUser"   required="true"  type="string" rules="noZeroLengthString,validEmail"  invalidMessage="failed_data_validation_email"    hint="Key matching the 'accounts' table."> 
<cfproperty name="loginEmail"  required="true"  type="string" rules="noZeroLengthString,validEmail"  invalidMessage="failed_data_validation_email"    hint="E-mail address."> 
<cfproperty name="password"   required="true"  type="string" rules="noZeroLengthString,validPassword" invalidMessage="failed_data_validation_password"   hint="Password stored in a SHA-512 hash."> 

<cffunction name="init" output="false" returntype="userBean" hint="Initalizes the userBean with default values."> 
    <cfset variables.instance    = structNew()> 
    <cfset variables.instance.IDUser  = 0> 
    <cfset variables.instance.loginEmail = ""> 
    <cfset variables.instance.password  = ""> 
    <cfreturn this> 
</cffunction> 

<!--- SET LOGIN ---> 
<cffunction name="setLoginEmail" access="public" returntype="void" output="false"> 
    <cfargument name="email" type="string" required="true" /> 
    <cfset variables.instance.loginEmail = trim(arguments.email) /> 
</cffunction> 
<cffunction name="getLoginEmail" access="public" returntype="string" output="false"> 
    <cfreturn variables.instance.loginEmail /> 
</cffunction> 

<!--- ID ---> 
<cffunction name="setIDUser" access="public" returntype="void" output="false"> 
    <cfargument name="id" type="numeric" required="true" /> 
    <cfset variables.instance.IDUser = arguments.id /> 
</cffunction> 
<cffunction name="getIDUser" access="public" returntype="numeric" output="false"> 
    <cfreturn variables.instance.IDUser /> 
</cffunction> 

<!--- PASSWORD ---> 
<cffunction name="setPassword" access="public" returntype="void" output="false"> 
    <cfargument name="password" type="string" required="true" /> 
    <cfset var pw = arguments.password> 
    <cfif len(pw) EQ 0> 
     <cfset variables.instance.password = ""> 
    <cfelse> 
     <!---><cfset variables.instance.password = hash(arguments.password, "SHA-512") />---> 
     <cfset variables.instance.password = arguments.password> 
    </cfif> 
</cffunction> 
<cffunction name="getPassword" access="public" returntype="string" output="false"> 
    <cfreturn variables.instance.password /> 
</cffunction> 

<!--- MOMENTO ---> 
<cffunction name="setMomento" access="public" returntype="void" output="false"> 
    <cfargument name="momento" type="struct" required="true" /> 
    <cfset variables.instance = arguments.momento> 
</cffunction> 
<cffunction name="getMomento" access="public" returntype="struct" output="false"> 
    <cfreturn variables.instance /> 
</cffunction> 

Cheers,

Aaron Greenlee My Site