0

私は走っていColdfusion8/MySQL 5.0.88ます。

データベースに 2 つのテーブルがあります。

modules
textblocks

私のサイトは複数の言語を実行しているため、ユーザーが選択した言語に応じてデータベースからテキストブロックをロードするために、すべてのページの先頭でこれを行っています。

<cfquery datasource="#Session.datasource#" name="texte">
   SELECT *
   FROM textblocks
   WHERE lang = <cfqueryparam value = "#Session.lang#" cfsqltype="cf_sql_varchar" maxlength="2">  
</cfquery>
<cfoutput query="texte">
    <cfset "#trim(label)#" = "#trim(content)#">
</cfoutput>

labelテキストブロックが必要な場合は、次のように単純に使用できます。

<cfoutput>#tx_hello_world#</cfoutput>

私の問題は、モジュールのリストを含む 2 番目のテーブルにあります。

各モジュールには独自の説明があります (ヘッダー、サブヘッダー、情報、箇条書き 1 ~ 5)。すべてのモジュール (25) をループlabelsする必要があるため、単一のループを実行しlabelsてデータベースから出力することを期待して、データベースに保存しました。残念ながらlabel123リターンを出力しています

 #label123#

vs私が望んでいる

 "text from table textblocks stored at label123"

質問:
「動的変数」を MySQL に保存し、これらを出力する際に​​、それらの基になる値を取得することは可能ですか? そうでない場合、「これがモジュールAの場合、テキストtx_module_a_titleを取得し、そうでない場合は...」と言わずに、単一のループで25個のモジュールを出力するより良いアプローチは何ですか?

ありがとう!

編集:
だから私はこれをすべてのループで実行しなければならないことを避けたいと思っています:

<cfif mods.module_name EQ "agents">
    <cfset variables.module_header = tx_module_b2b_agents_title>
    <cfset variables.module_subheader = tx_module_b2b_agents>
    <cfset variables.module_info = tx_module_b2b_agents_info>
    <cfset variables.module_bull_1 = tx_module_b2b_agn_accounts>
    <cfset variables.module_bull_2 = tx_module_b2b_agn_price_clients>
    <cfset variables.module_bull_3 = tx_module_b2b_agn_client_mgt>
    <cfset variables.module_bull_4 = tx_module_b2b_agn_create_retailer>
    <cfset variables.module_bull_5 = tx_module_b2b_exp_grace>
    <cfset variables.module_usage_tx = tx_vertreter/tx_gen_month>
<cfelseif mods.module_name EQ "preorder">
    <cfset variables.module_header = tx_module_b2b_preorder_title>
    <cfset variables.module_subheader = tx_module_b2b_preorder>
    <cfset variables.module_info = tx_module_b2b_preord_info>
    <cfset variables.module_bull_1 = tx_module_b2b_pre_split_type>
    <cfset variables.module_bull_2 = tx_module_b2b_pre_qty_y_n>
    <cfset variables.module_bull_3 = tx_module_b2b_pre_deliverydate>
    <cfset variables.module_bull_4 = tx_module_b2b_exp_grace>
    <cfset variables.module_bull_5 = "">
    <cfset variables.module_usage_tx = tx_gen_month >
<cfelseif mods.module_name EQ "export">
    <cfset variables.module_header = tx_module_b2b_export_title>
    <cfset variables.module_subheader = tx_module_b2b_export>
    <cfset variables.module_info = tx_module_b2b_export_info>
    <cfset variables.module_bull_1 = tx_module_b2b_exp_pricelists>
    <cfset variables.module_bull_2 = tx_module_b2b_exp_currencies>
    <cfset variables.module_bull_3 = tx_module_b2b_exp_customerlist>
    <cfset variables.module_bull_4 = tx_module_b2b_exp_regional_assortme>
    <cfset variables.module_bull_5 = tx_module_b2b_exp_grace>
    <cfset variables.module_usage_tx = tx_gen_month>
... 22 else-ifs to go
</cfif>

tx_データベースモジュールレコードの値の後ろにテキストブロックを保存できれば、そこから値を取得できます。

4

3 に答える 3

1

データベースからコンテンツを出力するときは、コンテンツを使用de()evalaute()て変数を処理できます。ネストされた組み合わせを使用する必要がある可能性があります。正確な構文は忘れました。 De(evaluate('#var#'))またはそのようなもの。

#ただし、コンテンツに var以外のものがある場合、これは問題になります。代わりにレキシコンを使用することをお勧めします。この記事を参照してくださいコンテンツ管理: 動的コンテンツの処理

于 2012-09-30T14:03:43.933 に答える
1

テキストクエリに変数コンテンツが含まれていると仮定すると、次のことができます。

<cfloopquery="texte">
    <cfset variables[trim(texte.label)] = trim(texte[content][texte.currentrow])>
</cfloop>

クエリは、別の構造のように参照できる構造であり、組み込みの currentrow 属性を使用して、構造内の currentrow を参照できます。

質問を読み直した後、コンテキストがモジュール テーブルに保存されているように見えますか? それならできます。いずれにせよ、それは機能しますが、可能な限り評価を使用しないようにする必要があります。

<cfloop query="texte">
  <cfloop query="modulesquery">
    <cfset variables[trim(texte.label)] = trim(modulesquery[content][modulesquery.currentrow])>
 </cfloop>
</cfloop>
于 2012-09-30T15:08:51.793 に答える
0

私はこのビットに焦点を当てるつもりです:

質問: 「動的変数」を MySQL に保存し、これらを出力する際に​​、それらの基になる値を取得することは可能ですか?

私がおそらく行うことは、テキストをファイルとして保存し、ファイルへのパスをDBに保存することです。次に、ファイルを処理するために CF を取得する必要がある場合 (変数を解決できる唯一の方法) は、DB からパスを取得し、そのパスにファイルを含めるだけです。

テキストをDBに入れる必要がある場合は、DBから読み込んでファイルに書き込んでから、ファイルを含める必要があります。CF 変数を処理するには、CF で処理する必要があり、そのためにはファイルを ColdFusion に渡す必要があります。それでおしまい。

ただし、ファイルを実行する前にコンパイルする必要があり、コンパイルプロセスが比較的遅いため、ファイルをあちこちに書き込んで必要なたびに含めるのは遅くなります。

これを回避する方法は、ファイルが必要になるたびにではなく、変更されたときにのみファイルを書き込むことです。ほとんどの Web サイトでは、Web サイトの仕組みの性質上、データは変更されるよりも桁違いに頻繁に読み取られます。

于 2012-09-30T18:07:39.230 に答える