一个 application.cfm 中可以有多个 cfapplication 吗?

发布于 2025-01-02 19:34:27 字数 2510 浏览 1 评论 0原文

我有一个带有 application.cfm 的 Coldfusion 站点。它定义了一个 cfapplication:

<cfapplication name="FhaApp" clientmanagement="no"
           sessionmanagement="yes" sessiontimeout="#createTimeSpan(0,0,360,0)#">

<cflock timeout="120" name="#session.sessionID#" type="exclusive">
<cfcookie name="CFID" value="#session.CFID#" >
<cfcookie name="CFTOKEN" value="#session.cftoken#" >
</cflock>
<cfparam name="session.fromwhere" default="">
<cfif #cgi.SCRIPT_NAME# contains 'default-partner-'>
    <cfif not ISDEFINED("cookie.fromwhere")>
<cfcookie name="fromwhere" value="#right(cgi.SCRIPT_NAME,         (len(cgi.SCRIPT_NAME)-1))#" expires="30">
    <cfset session.fromwhere = #right(cgi.SCRIPT_NAME,(len(cgi.SCRIPT_NAME)-1))#>
    </cfif> 
 </cfif>

 <cfset datasourcename="fha47">

 <cfparam name="application.dsn" default="fha47">

 <cfparam name="session.loggedin" default="false">
 <cfparam name="session.ppcid" default="101">
 <cfparam name="session.cid" default="FHA">

我想添加另一个 cfapplication,如下所示:

<cfapplication name = "QSvalues" 
sessionTimeout = "#CreateTimeSpan(0,0, 0, 60)#" 
sessionManagement = "yes">


<cflock scope = "Session" 
timeout = "30" type = "Exclusive">
<cfif NOT IsDefined("session.prop_st")>
    <cfset session.prop_st = "">
</cfif>
<cfif NOT IsDefined("session.prop_zip")>
    <cfset session.prop_zip = "">
</cfif>
<cfif NOT IsDefined("session.address")>
    <cfset session.address = "">
</cfif>
<cfif NOT IsDefined("session.email")>
    <cfset session.email = "">
</cfif>
<cfif NOT IsDefined("session.fname")>
    <cfset session.fname = "">
</cfif>
<cfif NOT IsDefined("session.lname")>
    <cfset session.lname = "">
</cfif>
<cfif NOT IsDefined("session.pri_phone_1")>
    <cfset session.pri_phone_1 = "">
</cfif>
<cfif NOT IsDefined("session.pri_phone_2")>
    <cfset session.pri_phone_2 = "">
</cfif>
<cfif NOT IsDefined("session.pri_phone_3")>
    <cfset session.pri_phone_3 = "">
</cfif>
</cflock>

<cflock scope = "Application" timeout = "30" type = "Exclusive">
<cfif NOT IsDefined("application.number")>
    <cfset application.number = 0>
</cfif>
</cflock>

我的问题是,您可以在主 application.cfm 中定义两个单独的 cfapplication 吗?

I have a coldfusion site with an application.cfm. It has a cfapplication defined in it:

<cfapplication name="FhaApp" clientmanagement="no"
           sessionmanagement="yes" sessiontimeout="#createTimeSpan(0,0,360,0)#">

<cflock timeout="120" name="#session.sessionID#" type="exclusive">
<cfcookie name="CFID" value="#session.CFID#" >
<cfcookie name="CFTOKEN" value="#session.cftoken#" >
</cflock>
<cfparam name="session.fromwhere" default="">
<cfif #cgi.SCRIPT_NAME# contains 'default-partner-'>
    <cfif not ISDEFINED("cookie.fromwhere")>
<cfcookie name="fromwhere" value="#right(cgi.SCRIPT_NAME,         (len(cgi.SCRIPT_NAME)-1))#" expires="30">
    <cfset session.fromwhere = #right(cgi.SCRIPT_NAME,(len(cgi.SCRIPT_NAME)-1))#>
    </cfif> 
 </cfif>

 <cfset datasourcename="fha47">

 <cfparam name="application.dsn" default="fha47">

 <cfparam name="session.loggedin" default="false">
 <cfparam name="session.ppcid" default="101">
 <cfparam name="session.cid" default="FHA">

I want to add another cfapplication that looks like this:

<cfapplication name = "QSvalues" 
sessionTimeout = "#CreateTimeSpan(0,0, 0, 60)#" 
sessionManagement = "yes">


<cflock scope = "Session" 
timeout = "30" type = "Exclusive">
<cfif NOT IsDefined("session.prop_st")>
    <cfset session.prop_st = "">
</cfif>
<cfif NOT IsDefined("session.prop_zip")>
    <cfset session.prop_zip = "">
</cfif>
<cfif NOT IsDefined("session.address")>
    <cfset session.address = "">
</cfif>
<cfif NOT IsDefined("session.email")>
    <cfset session.email = "">
</cfif>
<cfif NOT IsDefined("session.fname")>
    <cfset session.fname = "">
</cfif>
<cfif NOT IsDefined("session.lname")>
    <cfset session.lname = "">
</cfif>
<cfif NOT IsDefined("session.pri_phone_1")>
    <cfset session.pri_phone_1 = "">
</cfif>
<cfif NOT IsDefined("session.pri_phone_2")>
    <cfset session.pri_phone_2 = "">
</cfif>
<cfif NOT IsDefined("session.pri_phone_3")>
    <cfset session.pri_phone_3 = "">
</cfif>
</cflock>

<cflock scope = "Application" timeout = "30" type = "Exclusive">
<cfif NOT IsDefined("application.number")>
    <cfset application.number = 0>
</cfif>
</cflock>

My question is, can you define two separate cfapplication in the main application.cfm?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

葵雨 2025-01-09 19:34:28

使用 Sean Corfield 的方法在扩展根 Application.cfc 的子文件夹中创建 Application.cfc。

https://stackoverflow.com/a/307441/11047

您的根 Application.cfc 将包含所有主应用程序和需要会话变量。您的子目录的 Application.cfc 将包含“QSvalues”应用程序的所有应用程序和会话变量。然而,这些变量将位于 application.qsValues 和 session.qsValues 中。

application.qsValues.number,而不是 application.number。
session.qsValues.prop_st,而不是 session.prop_st。

这样做,您可以拥有任意数量的“子应用程序”,但它们都将存在于单个 APPLICATION.NAME 中。

Use Sean Corfield's approach to create an Application.cfc in a sub-folder which extends your root Application.cfc.

https://stackoverflow.com/a/307441/11047

Your root Application.cfc will contain all of the primary application and session variables needed. Your sub-directory's Application.cfc will contain all of the application and session variables for your "QSvalues" application. However these variables will sit in application.qsValues and session.qsValues.

application.qsValues.number, not application.number.
session.qsValues.prop_st, not session.prop_st.

Doing this, you can have as many "sub-applications" as you want, but they'll all exist within a single APPLICATION.NAME.

顾北清歌寒 2025-01-09 19:34:27

我不完全确定您为什么想要或需要第二个 cfapplication;从您的代码或解释中并不清楚。我认为您可能可以在其中放置另一个,但它可能会覆盖前一个。

此外,在您的代码中,您所做的只是写入应用程序范围......这并不是真正声明另一个 cfapplication。

不过有几个提示...您的会话值的大 cfif 区域,只需使用 cfparam:

<cfparam name="session.prop_st" default="">

这样,如果它尚不存在,则会创建它。

另外,如果您使用最新的 ColdFusion,则无需围绕会话范围进行 cflock。您应该锁定应用程序范围设置,但由于您在 Application.cfm 中设置它们,所以这有点愚蠢..我会使用另一个范围,例如请求范围。

在您的 cfif cgi.script_name 上,您不需要在该变量周围使用 # 符号。您唯一需要它们的时候是当它们被引用或在 cfoutput 中输出时(或者与 Evaluate() 一起使用来创建动态变量时)。

我希望这有帮助。

I'm not entirely sure why you would want or need the second cfapplication; it's not really clear from your code or explanation. I think you could probably put another one in there, but it would likely override the previous one.

Besides, in your code all you're doing is writing to the application scope.. that's not really declaring another cfapplication.

A couple of tips though... your big cfif area for the session values, just use cfparam:

<cfparam name="session.prop_st" default="">

That way if it doesn't already exist, it will be created.

Also, if you're using the latest ColdFusion, you don't need to cflock around session scopes. You should be locking around the application scope settings, but since you're setting them in Application.cfm, it's kinda silly.. I would use another scope, like the request scope.

On your cfif cgi.script_name, you don't need # signs around that variable. The only times you need them are when they're quoted or are being outputted in a cfoutput (or when used with Evaluate() to create dynamic variables).

I hope this helps.

我的奇迹 2025-01-09 19:34:27

好吧,从技术上来说你可以做到这一点。结果是与第一个标签调用关联的应用程序、客户端和会话范围仅在第二个标签调用之前可用。此时,对这些范围的所有后续引用都将引用后一个标记定义的上下文。然而,这样做是个好主意的情况并不多。

Well, you can do this, technically. The result would be that the Application, client and session scopes associated with the first tag call would be available only until the second tag call. At that point, all subsequent references to those scopes would refer to the context defined by the latter tag. It's not too many cases where doing this is a great idea, however.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文