我想处理当该模板不存在时用户点击 /somePage.cfm 的 url 并使用来自另一个目录的模板的场景。我知道我可以通过在 apache 等中重写来做到这一点,但我真的不想在其中存储逻辑,所以我尝试覆盖onTemplateMissing
我的 Application.cfc 中的行为。
它似乎在我的测试中运行良好,但我担心通过这个 hacky 解决方案我会缩短一些我还没有看到的部分(例如我目前没有使用的方法,如 onSessionStart 等)和将来可能会遇到问题。
这是我目前正在做的事情:
<cffunction name="onMissingTemplate">
<cfargument name="targetPage" />
<!--- Handle any templates that we're really loading from elsewhere --->
<cfif isFooTemplate(arguments.targetPage)>
<cfset onRequestStart(arguments.targetPage) />
<cfset onRequest(arguments.targetPage) />
<cfset onRequestEnd(arguments.targetPage) />
<cfreturn true />
</cfif>
<cfreturn false />
</cffunction>
请注意,同样在我的方法中,我正在对返回 trueonRequest
的模板进行进一步处理。isFooTemplate()