2009-03-06 9 views
9

私は共有するCFCのベストプラクティスのリストを作成しています。ColdFusion CFCベスト/推奨プラクティスのコレクション?

そこには数多くの記事がありますが、ここでは経験を通して学んだ1つの場所に何かのヒントやヒントをまとめるのはすごくいいと思っていました。

私はここにいくつかのリンクを追加するつもりですが、私は最高のものは、検索することができる長い記事ではないと思います。

CFC Best Practices

Macromedia CFC Best Practices

更新:これはコミュニティのwikiに行われた

+0

1)は常にあなたがプレスを通知する前に、あなたの結果が再現可能であることを確認... – Shog9

+0

これはコミュニティウィキのようなものでしょうか? 「ベスト」はほとんどの問題であるため、より正確な単語が通常は「お勧め」または「ファッション」である場合は、「ベスト」を使用することに反対するため、私は改善された名前を申請したいと思います。コンテキスト。 –

+0

ピーター、やった! –

答えて

0

私はその時点でのプロパティをキャプチャするためにMOMENTOSを使用してについての投稿を見ていないColdBox Frameworkを使用する前に、しかし、私の豆はすべてgetMomento()とsetMomento()メソッドを持っています。私はこれを、Beanの情報をDAOの他のオブジェクトに渡す必要がある人にとって、ベストプラクティスとして推奨します。

私のテストでは、瞬間を取得する方が、Beanを渡してプロパティを取得するよりもはるかに高速です。次に例を示します。

<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> 

乾杯、

アーロン・グリーンリー My Site

関連する問題