मुझे एप्लीकेशन.cfc में मैपिंग सेट करने में समस्या है। हमारे पास विविध सर्वर (देव, क्यूएस, प्रोड) प्रत्येक अलग-अलग पैथ के साथ है। मैं विन्यास फाइल के माध्यम से सर्वर विशिष्ट पैच और चर सेट करना चाहता हूँ। एप्लिकेशन स्टार्ट पर आप आईएनआई फ़ाइल पढ़ते हैं और अपना सिस्टम सेटअप करते हैं। http://www.raymondcamden.com/index.cfm/2005/8/26/ColdFusion-101-Config-Files-AGoGo यह ठीक काम करता है। एक सामान्य CFM फ़ाइल मेंमैं बाहरी संपत्ति फ़ाइल से एप्लिकेशन.cfc में मैपिंग कैसे शामिल कर सकता हूं?
<!--- in Application.cfc --->
<cfset this.mappings['/components'] = "D:\Inetpub\wwwroot\myApp\components">
समवेयर आई के माध्यम से एक सीएफसी नामित परीक्षण instatiate:
Normaly आप मैपिंग Applcation.cfc में इस तरह सेट
<cfset t = createObject("component", "components.test")>
मैं केवल मैपिंग सेट करना चाहते हैं एक बार पर onApplicationsStart
<cffunction
name="OnApplicationStart"
access="public"
returntype="boolean"
output="false"
hint="Fires when the application is first created.">
<!---create structure to hold configuration settings--->
<cfset ini = structNew()>
<cfset ini.iniFile = expandPath("./ApplicationProperties.ini")>
<cfset application.ini = ini>
<!--- read ini file --->
<cfset sections = getProfileSections(application.ini.iniFile)>
<cfloop index="key" list="#sections.mappings#">
<cfset this.mappings[key] = getProfileString(application.ini.iniFile, "mappings", key)>
</cfloop>
लेकिन यह काम नहीं करता है क्योंकि यह। मैपिंग खाली है और अगला अनुरोध है। :(
को OnRequestStart
<!--- read ini file --->
<cfset sections = getProfileSections(application.ini.iniFile)>
<cfloop index="key" list="#sections.mappings#">
<cfset this.mappings[key] = getProfileString(application.ini.iniFile, "mappings", key)>
</cfloop>
मुझे लगता है कि घटक नहीं पाया जा सकता है कोई त्रुटि मिलती है इस लाना। यह अजीब है।
आवेदन गुंजाइश में struct लाना
<cfloop index="key" list="#sections.mappings#">
<cfset APPLICATION.mappings[key] = getProfileString(application.ini.iniFile, "mappings", key)>
</cfloop>
मेरे घटक को कैसे कॉल करें?
<cfset t = createObject("component", "application.components.test")>
काम नहीं करता है।
तो मेरे पास 3 लक्ष्य हैं।
- sourcecode में आसान उपयोग ApplicationStart पर INI फ़ाइल
- से सभी pathes और मैपिंग पढ़ने उन्हें पढ़ एक बार।
बहुत बहुत धन्यवाद यह मुझे सही दिशा में एक बड़ा कदम लाता है। लेकिन इस पंक्ति के कारण मुझे वेब्रॉट में नहीं होने वाले पृष्ठ को कॉल करते समय "त्रुटि नहीं मिली" प्राप्त होती है। –
inog
मैं इसे हार्डकोड नहीं करना चाहता हूं। इस चिकन या अंडा दुविधा के लिए कोई विचार? – inog
Thats क्योंकि वर्तमान फ़ाइल स्थान के सापेक्ष इसकी कॉलिंग विस्तारपथ()। आपको एक पूर्ण पथ का उपयोग करना होगा, मैंने यह जवाब –