coldfusion 10中有Application.cfc
的新设置:
this.smtpServersettings = as a structure
我可以在这里对这些值进行硬编码,但是我将我的邮件设置保存在数据库中,我想在这里使用这些值,是否可以在此处使用数据库设置。
这是我的更新:
<cfcomponent hint="File for the Website" output="false">
<cfsetting showdebugoutput="no">
<cfset this.name = "myProject1">
<cfset this.applicationTimeout = createTimeSpan(2,0,0,0)>
<cfset this.clientmanagement= "yes">
<cfset this.loginstorage = "session">
<cfset this.sessionmanagement = "yes">
<cfset this.sessiontimeout = CreateTimeSpan(0,0,40,0) />
<cfset this.setClientCookies = "yes">
<cfset this.scriptProtect = "all">
<cfset this.setDomainCookies = true>
<cfset this.customTagPaths = ExpandPath('customtags')>
<cfset this.datasource = {name="myDB"}>
<cfset this.smtpServersettings = {structur as username,password and mail settings}>
但是这个值需要通过数据库,你能告诉我一个例子吗
答案 0 :(得分:1)
是的,您应该能够从数据库查询中设置this.smtpServersettings
变量的值。对于它的价值,我认为自ColdFusion 9以来该设置已经可用。
您需要做的就是以下内容。
this.smtpServersettings
变量分配给新结构当然,如果/当数据库查询失败时,您需要添加一些代码来执行某些操作。
问题更新后更新
只需执行以下操作(伪代码):
<cfcomponent hint="File for the Website" output="false">
<cfsetting showdebugoutput="no">
<cfset this.name = "myProject1">
<cfset this.applicationTimeout = createTimeSpan(2,0,0,0)>
<cfset this.clientmanagement= "yes">
<cfset this.loginstorage = "session">
<cfset this.sessionmanagement = "yes">
<cfset this.sessiontimeout = CreateTimeSpan(0,0,40,0) />
<cfset this.setClientCookies = "yes">
<cfset this.scriptProtect = "all">
<cfset this.setDomainCookies = true>
<cfset this.customTagPaths = ExpandPath('customtags')>
<cfset this.datasource = {name="myDB"}>
<!--- run your query here --->
<!--- check your query and do something appropriate if/when it fails --->
<cfset this.MyStructure = StructNew()>
<cfset this.MyStructure.server = this.MyQuery.ServerNameVariable>
<cfset this.MyStructure.username = this.MyQuery.UserNameVariable>
<cfset this.MyStructure.password = this.MyQuery.PasswordVariable>
<cfset this.smtpServersettings = this.MyStructure>
您还需要注意,以这种方式执行此操作将在每个页面请求上运行该查询。确保它运行得很快。