Why I can't call method in Coldfusion component?

2.7k views Asked by At

I'm using Coldfusion8 and am stuck trying to call a component. This worked up until a few days ago and although I can't recall changing anything, all my calls to this component now fail.

Here the code:

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

Nothing special really except maybe for passing a struct are argument.

I'm getting the following error:

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

It exists allright... so what can I do to try and access it?

Thanks for help!

EDIT:
Both files are in the same folder called services. I have a mapping for this folder in my application.cfc

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

But trying to call the component like so:

services.form_mailer_user
services.form_mailer_user.cfc

also does not work.

EDIT:
My 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>

EDIT:
I think I'm getting closer. I have another mailer (same folder) and I just swapped this one in replacing my

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

Now Coldfusion can't find the method, but this means it found the cfc. Could it be an error inside my mailer.cfc then?

SOLUTION:
I'm afraid to tell...

Typo in the filename from_mailer_user ... Thanks everyone for helping out!

2

There are 2 answers

1
Matt Tholey On BEST ANSWER

if the CFC and CFM file are not in the same directory you need to add the directory name where the CFC is located with a dot. See below. (directory.form_mailer_user)

2
boycaught On

Add the attribute access="public" in the definition of the methods you can't "see" like this:

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