使用onRequestEnd()和Application.cfm文件进行Coldfusion [英] Coldfusion using onRequestEnd() with Application.cfm files

查看:135
本文介绍了使用onRequestEnd()和Application.cfm文件进行Coldfusion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用基于Application.cfm文件而不是Application.cfc文件构建的旧版应用程序中工作.

I'm working in a legacy app that was built upon the use of Application.cfm files rather than Application.cfc files.

处理请求后,需要能够运行代码. (基本上,我想使用<cfhtmlhead>标记将一些Javascript和CSS文件注入到每个已加载的文档中.在使用GreaseMonkey用户脚本进行此操作之前,但是最好在服务器端进行操作.)

There is a need to be able to run code after a request has processed. (Basically, I am wanting to use the <cfhtmlhead> tag to inject some Javascript and CSS files into every loaded document. Before I was doing this with a GreaseMonkey user script, but something server-side would be best.)

从我读到的内容来看,我认为我应该可以使用onRequestEnd()函数来完成此操作,但是,我只见过关于Application.cfc文件的引用.我读过您可以将onRequestEnd.cfm文件与Application.cfm文件放在同一目录中,以将其注册到onRequestEnd()函数,但是系统不会映射到一个Application.cfm文件(即,我会必须将此onRequestEnd.cfm文件放在很多目录中.

From what I read, I think I should be able to do this with the onRequestEnd() function, however, I've only ever seen that referenced in regards to Application.cfc files. I have read that you can put an onRequestEnd.cfm file in the same directory as an Application.cfm file to have it register it to the onRequestEnd() function, but the system does not map to one Application.cfm file (i.e. I would have to throw this onRequestEnd.cfm file in a lot of directories).

是否还有其他方法可以使用Application.cfm设置来注册此onRequestEnd()函数?如果有问题,我们将运行Coldfusion 9.

Is there some other way to register this onRequestEnd() function using an Application.cfm setup? In case it matters, we are running Coldfusion 9.

推荐答案

仅说明一下,只有在使用Application.cfc文件时,onRequestEnd()方法才可用.

Just to clarify, the onRequestEnd() method is only available if you are utilizing the Application.cfc file.

OnRequestEnd.cfm文件的确确实像Application.cfm文件那样工作,因为ColdFusion会自动查找它并在找到后处理它的内容.请注意,如果您的应用程序有Application.cfc文件,则您将无法使用OnRequestEnd.cfm页面.因此,假设您的应用程序没有Application.cfc文件,而仅使用Application.cfm文件,然后OnRequestEnd.cfm文件将为您工作.您需要做的就是将要在页面请求之后执行的CFML代码插入该文件.

The OnRequestEnd.cfm file does indeed work like the Application.cfm file in that ColdFusion automatically looks for it and will process it's contents when found. Do note that you cannot use an OnRequestEnd.cfm page if you have an Application.cfc file for your application. So assuming that you have no Application.cfc files for your application and are only using Application.cfm files then the OnRequestEnd.cfm file should work for you. All you need to do is insert the CFML code that you would like to be executed after the page request into that file.

如果您有多个Application.cfm文件分布在各个文件夹中,那么是的,还需要在这些目录中复制/创建OnRequestEnd.cfm文件.您也许可以在那些目录中复制 stub OnRequestEnd.cfm文件,这些文件仅从另一个位置执行cfinclude您的实际代码.至少以这种方式,一旦所有 stub 文件都保存在那里,您就可以在一个地方修改代码.

If you have several Application.cfm files spread out in various folders then, yes, you will also need to copy/create the OnRequestEnd.cfm files in those directories as well. You might be able to copy stub OnRequestEnd.cfm files in those directories that do nothing more than cfinclude your actual code from another, single, location. At least that way once you have all of the stub files out there you can modify the code in a single place.

请参阅构建应用程序的文档(已编写)对于ColdFusion 8,但仍适用相同的规则).如果该页面被删除,则以下为相关文本:

See the documentation for Structuring an application (it was written for ColdFusion 8 but the same rules still apply). In case that page is taken down, here is the relevant text:

ColdFusion如何查找和处理应用程序定义页面

ColdFusion使用以下规则来定位和处理定义特定于应用程序的元素的Application.cfc,Application.cfm和OnRequestEnd.cfm页面. ColdFusion定位这些文件的方式有助于确定如何构造应用程序.

ColdFusion uses the following rules to locate and process the Application.cfc, Application.cfm, and OnRequestEnd.cfm pages that define application-specific elements. The way ColdFusion locates these files helps determine how you structure an application.

每次ColdFusion处理页面请求时,它都会执行以下操作:

Each time ColdFusion processes a page request it does the following:

  1. 当ColdFusion开始处理请求时,它将执行以下操作:

  1. When ColdFusion starts processing the request, it does the following:

  • 它将在页面目录中搜索名为Application.cfc的文件.如果存在,它将创建CFC的新实例,处理初始事件,并停止搜索. (ColdFusion创建CFC的新实例,并为每个请求处理其初始化代码.)
  • 如果请求的页面目录没有Application.cfc文件,它将检查目录中是否有Application.cfm文件.如果存在,则ColdFusion逻辑上在请求页面的开头包含Application.cfm页面,并停止进一步搜索.
  • 如果所请求页面的目录中没有Application.cfc或Application.cfm文件,ColdFusion将在目录树中搜索并首先在每个目录中检查Application.cfc文件,然后在未找到目录的情况下检查Application .cfm页,直到到达根目录(例如C :).找到Application.cfc或Application.cfm文件后,它将处理该页面并停止搜索.
  • It searches the page's directory for a file named Application.cfc. If one exists, it creates a new instance of the CFC, processes the initial events, and stops searching. (ColdFusion creates a new instance of the CFC and processes its initialization code for each request.)
  • If the requested page's directory does not have an Application.cfc file, it checks the directory for an Application.cfm file. If one exists, ColdFusion logically includes the Application.cfm page at the beginning of the requested page and stops searching further.
  • If the requested page's directory does not have an Application.cfc or Application.cfm file, ColdFusion searches up the directory tree and checks each directory first for an Application.cfc file and then, if one is not found, for an Application.cfm page, until it reaches the root directory (such as C:). When it finds an Application.cfc or Application.cfm file, it processes the page and stops searching.
  • 如果您有Application.cfc,ColdFusion将处理CFC的onRequestEnd方法并释放CFC实例.
  • 如果您没有Application.cfc,但是具有Application.cfm页面,则ColdFusion在与ColdFusion用于当前页面的Application.cfm页面相同的目录中查找OnRequestEnd.cfm. ColdFusion不会搜索该目录之外的内容,因此它不会运行驻留在另一个目录中的OnRequestEnd.cfm页面.另外,如果应用程序页面上有错误或异常,或者应用程序页面执行cfabort或cfexit标记,则OnRequestEnd.cfm页面不会运行.

以下规则确定ColdFusion如何处理应用程序页面和设置:

The following rules determine how ColdFusion processes application pages and settings:

  • ColdFusion对于每个请求仅处理一个Application.cfc或Application.cfm页面.如果ColdFusion页面的cfinclude标记指向另一个ColdFusion页面,则当ColdFusion包含附加页面时,它不会搜索Application.cfc或Application.cfm页面.
  • 如果ColdFusion页面具有cfapplication标记,则它将首先处理任何Application.cfc或Application.cfm,然后处理cfapplication标记.该标记可以覆盖应用程序文件中的设置,包括应用程序名称和cfapplication标记属性设置的行为.
  • 您可以具有使用相同应用程序名称的多个Application.cfc文件,Application.cfm文件和cfapplication标签.在这种情况下,具有相同名称的所有页面共享相同的应用程序设置和应用程序范围,并且可以设置和获取该范围中的所有变量.如果会话之间的超时设置等文件之间的设置不同,ColdFusion将使用cfapplication标记或最近处理的文件的参数设置.
  • ColdFusion processes only one Application.cfc or Application.cfm page for each request. If a ColdFusion page has a cfinclude tag pointing to an additional ColdFusion page, ColdFusion does not search for an Application.cfc or Application.cfm page when it includes the additional page.
  • If a ColdFusion page has a cfapplication tag, it first processes any Application.cfc or Application.cfm, and then processes the cfapplication tag. The tag can override the settings from the application files, including the application name and the behaviors set by the cfapplication tag attributes.
  • You can have multiple Application.cfc files, Application.cfm files, and cfapplication tags that use the same application name. In this case, all pages that have the same name share the same application settings and Application scope and can set and get all the variables in this scope. ColdFusion uses the parameter settings of the cfapplication tag or the most recently processed file, if the settings, such as the session time-out, differ among the files.

注意::如果您的应用程序在区分大小写的UNIX平台上运行,则必须使用大写字母拼写Application.cfc,Application.cfm和OnRequestEnd.cfm.

Note: If your application runs on a UNIX platform, which is case-sensitive, you must spell Application.cfc, Application.cfm, and OnRequestEnd.cfm with capital letters.

这篇关于使用onRequestEnd()和Application.cfm文件进行Coldfusion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆