Application.cfc设置DSN并调用该DSN [英] Application.cfc setting DSN and calling that DSN

查看:85
本文介绍了Application.cfc设置DSN并调用该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屋!

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