簡體   English   中英

為什么我不能在Coldfusion組件中調用方法?

[英]Why I can't call method in Coldfusion component?

我正在使用Coldfusion8而且我試圖調用一個組件。 這種情況一直持續到幾天前,雖然我不記得改變了什么,但我對這個組件的所有調用現在都失敗了。

這里的代碼:

<cfinvoke component="form_mailer_user" method="msg_contact">
     <cfinvokeargument name="userData" value="#Local.User#"/>
</cfinvoke>  

沒有什么特別的,除了可能傳遞結構是參數。

我收到以下錯誤:

 Could not find the ColdFusion Component or Interface form_mailer_user. 
 Ensure that the name is correct and that the component or interface exists

它存在,所以我該怎么辦才能嘗試訪問它?

感謝幫助!

編輯:
這兩個文件都在名為services的同一文件夾中。 我在application.cfc有這個文件夾的映射

THIS.mappings["/services"] = GetDirectoryFromPath( GetCurrentTemplatePath() ) & "services";

但試圖像這樣調用組件:

services.form_mailer_user
services.form_mailer_user.cfc

也行不通。

編輯:
我的application.cfc

<cfcomponent displayname="Application" output="false" hint="Application handler">   
    <cfscript>
        THIS.name = "abc";
        THIS.sessionManagement = "true";        
        THIS.sessionTimeout = createTimeSpan(0,2,0,0);
        THIS.s3.acceesKeyid = "___";
        THIS.s3.awsSecretKey = "___";
        // mappings
        THIS.mapping = {};
        THIS.mappings["/controllers"] = GetDirectoryFromPath( GetCurrentTemplatePath() ) & "controllers";
        THIS.mappings["/services"] = GetDirectoryFromPath( GetCurrentTemplatePath() ) & "services";
    </cfscript>

    <cffunction name="onApplicationStart" returnType="boolean" output="false" hint="">
        <cfscript>
            Application.strConfig = structNew();
            Application.strConfig.datasource = "___";
            Application.strConfig.rootDir = "test/members/";
            Application.strConfig.emailErrorMessaging = "on";
        // pre
            Session.activeSession = "No";
            Session.activeLog = "No";
        </cfscript>
        <cfreturn true />
    </cffunction>

    <cffunction name="onSessionStart" returnType="boolean" output="false" hint="session initalizer">
        <cfscript>
            var Local = {};
            Local.cfid = Session.cfid;
            Local.cftoken = Session.cftoken;
            StructClear( SESSION );
        </cfscript>

        <!---SESSION  --->
        <cfparam name="Session.log" default="">
        <cfparam name="Session.activeLog" default="No">
        <cfscript>
            Session.cfid = Local.cfid;
            Session.cftoken = Local.cftoken;
            Session.activeSession = "Yes";              
            Session.datasource = Application.strConfig.datasource;
            Session.testpath = "tes/";
            Session.tpu = "../";
            Session.bucketPath = "http://s3.amazonaws.com/";
            Session.bucketName = "___";
        </cfscript> 
        <cfreturn true />
    </cffunction>

    <cffunction name="onRequestStart" returnType="boolean" output="false" hint="Pre page processing!">         
        <cfscript>
            var LOCAL = {};             
        </cfscript> 
        <!--- DEBUG --->
        <!---
            <cfif structKeyExists(url,'reset')>
                <cfcache action="flush">
                <cfset OnApplicationStart() />
                <cfset THIS.OnSessionStart() />
            </cfif>
            --->
            <cfif len( Session.errMsgs ) EQ 0> 
                <cfinvoke component="services.errorMsg" method="createErrMsgsLog" returnvariable="errMsgs"></cfinvoke>
                <cfset Session.errMsgs = errMsgs> 
            </cfif> 
        <cfreturn true />
    </cffunction>
    <!--- custom functions --->
<cfinclude template="templates/tmp_functions.cfm">
</cfcomponent>

編輯
我想我越來越近了。 我有另一個郵件程序(相同的文件夾),我只是換了這個替換我的

 <cfinvoke component="form_mailer_other" method="msg_contact">
     <cfinvokeargument name="userData" value="#Local.User#"/>
</cfinvoke>

現在Coldfusion找不到方法,但這意味着它找到了cfc。 可能是我的mailer.cfc里面的錯誤嗎?

解:
我不敢告訴......

來自 _mailer_user的文件名中錯誤...感謝大家的幫助!

如果CFC和CFM文件不在同一目錄中,則需要使用點添加CFC所在的目錄名稱。 見下文。 (directory.form_mailer_user)

在您無法“看到”的方法定義中添加屬性access =“public” ,如下所示:

<cffunction name="onRequestStart" access="public" returnType="boolean" output="false" hint="Pre page processing!"> ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM