Application.cfc设置DSN并调用该DSN [英] Application.cfc setting DSN and calling that DSN
问题描述
已向我展示了如何使用Application.cfc而不是使用Application.cfm来做到这一点-很好,我喜欢学习新知识.但是,在进行更改后,我不知道如何使DSN正常工作.在我刚刚在Application.cfm文件中使用一组 DSN
之前.
I have been shown how to do this with Application.cfc instead of using the Application.cfm - that is fine, I like learning new stuff. Yet after I made the change I cannot figure out how to get the DSN working properly. Before I just used a set DSN
in the Application.cfm file.
<cfparam name="DSN" default="">
<cfset DSN = "krl" />
在这里喊出来:
<CFQUERY NAME="Inital" DATASOURCE="#DSN#">
SELECT Website_Name
FROM InitalizationData
</CFQUERY>
现在将其设置为:
component {
this.name = "app";
this.Sessionmanagement = true;
this.datasource = "krl";
public void function onSessionStart() {
// initialize cart
session.cart = [];
}
}
如何在查询中对其进行标注?
How do I call it out in my queries?
推荐答案
在 Application.cfc
内,通常会添加一个函数 onApplicationStart()
.然后,在该函数内定义
Inside Application.cfc
, you would usually add a function onApplicationStart()
. Then, inside that function define
application.dsn ="foo";
并像这样引用它:
< cfquery name ="test" datasource =#application.dsn#">
在CFC中将变量定义为 this.datasource
时, this
范围仅存在于该CFC的上下文中.无法从外部访问它.
When you define the variable as this.datasource
inside a CFC, the this
scope exists only in the context of that CFC. It's not accessible from outside it.
这篇关于Application.cfc设置DSN并调用该DSN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!