不足しているテンプレートをサーバーに処理させたいのはなぜですか? 私自身、アプリケーションごとに処理するのが好きです。一部のアプリケーションは、存在しないファイルにつながるリンクを持つべきではありません。他のアプリケーションは、そのコアの一部として動作する可能性があります。
adobe の docsからそのまま使用できます (この情報は cf8 docs から誤って引っ張ってきましたが、リンクは現在の docs であり、結果はほぼ同じです。
<cffunction name="onMissingTemplate" returnType="boolean">
<cfargument type="string" name="targetPage" required=true/>
...
<cfreturn BooleanValue />
</cffunction>
私のプロジェクトのいくつかでは、すべてのコンテンツをデータベースに格納する CMS (Content-Management-System) を作成しました。
CMSPages
------------
PID PTitle PFile PContent
1 Home /index.cfm <b>Hey!</b> Welcome to our gollygizmo website.
そして、私 (私の実際のコードでは、ドキュメント内で直接ではなく、実際に cfincludes を使用しています。どちらの方法でも実行できますが、インライン コードで説明するのが最も簡単でした)。
<cffunction name="onMissingTemplate" returnType="boolean">
<cfargument type="string" name="targetPage" required=true/>
<cftry>
<cfquery name="FindPage">
select * from CMSPages
where pFile = <cfqueryparam cfsqltype="nvarchar" value="#Arguments.targetPage#">
</cfquery>
<cfif FindPage.recordcount eq 1>
<cfoutput query="FindPage">show page stuffs</cfoutput>
<cfreturn true>
<cfelse>
<!--- Page not found, log some stuff or email stuff
include cgi data so you know where the link came from --->
Hey, this page doesn't exist, sorry about that.
<cfreturn true>
</cfif>
<cfcatch>
<!--- Something went wrong, log/email error info and --->
<cfreturn false>
<!--- We return false here to pass it back to the default error handler, which can be a handler set in cfadmin. --->
</cfcatch>
</cftry>
</cffunction>
このようなシナリオでは、クエリ名に基づいてクエリをキャッシュすることがおそらく有益です。次のようなことができます。
<cfquery name="local.FindPage#hash(arguments.targetpage)#" cachedWithin="...">
...
</cfquery>
<cfset request.FindPage=local["Findpage#hash(arguments.targetpage)#"]>
そのため、一般的な名前でドキュメントに簡単にアクセスできる場合でも、クエリは一意の名前でキャッシュされます。
ただし、サーバー中心の不足しているテンプレートの処理を引き続き好む場合は、 を検索するだけでここcold fusion admin missing template
にアクセスできます。
- ColdFusion Administrator で、[設定] をクリックして [サーバー設定] ページを表示します。
- エラー処理テンプレートを見つけるために ColdFusion が使用する絶対パスを指定します。