Skip to main content
Participating Frequently
April 30, 2009
Answered

Cfinterface question

  • April 30, 2009
  • 1 reply
  • 539 views

Hello,

I've created a cfinterface file and a cfcomponent file in the same folder. I've put the "implements=<interface file name>" in the cfcomponent tag. It doesn't seem to matter what I put in the implements path or in the cfinterface file. It just seems to ignore it. From the documentation, it states the definition in the cfcomponent must match the cfinterface that it implements, so I was thinking it would error in some way if it didn't match. Can someone tell me what I'm doing wrong? Thanks for the help.

Itest.cfc:

<cfinterface>
<cffunction name="test" access="remote" returntype="query" output="no">
       <cfargument name="param" type="string">
</cffunction>
</cfinterface>

Ctest.cfc:
<cfcomponent implements="Itest.cfc">
        <cffunction name="test" access="remote" returntype="query" output="no">
            <cfargument name="param" type="string">
           
            <cfquery name="testquery" datasource="#dsn#">
                    select id
                    from test1
                    where name = 'test1'
            </cfquery>
           
            <cfreturn #testquery#>
        </cffunction>
</cfcomponent>

    This topic has been closed for replies.
    Correct answer craigkaminsky

    vootmon,

    Question for you: What version of CF are you using?

    I created the following two CFCs on my machine.

    ITest.cfc

    <cfinterface displayName="ITest">

    <cffunction name="test" access="remote" output="false" returntype="string">

    <cfargument name="param" type="string" />

    </cffunction>

    </cfinterface>

    TestInt.cfc

    <cfcomponent output="false" implements="ITest">

    <cffunction name="test2" access="remote" returntype="string" output="false">

    <cfreturn "hello world" />

    </cffunction>

    </cfcomponent>

    index.cfm

    <cfscript>

    mycfc = createObject( "component", "TestInt" );

    </cfscript>

    <cfoutput>#mycfc.test2()#</cfoutput>

    When I run this in both CF 8.0.1 and Railo 3.1, I get the following error:

    Interfaces cannot have access="remote". On the value "public" is allowed.

    If I change the access in ITest.cfc to public, I get another error:

    TestInt.cfc does not implement the function test, which I did on purpose to test.

    After copying over/recreating the test function from the interface (with access="public" and the same parameter), it worked in CF 8 and Railo 3.1.

    This is the code that works:

    ITest.cfc

    <cfinterface displayName="ITest">

    <cffunction name="test" access="public" output="false" returntype="string">

    <cfargument name="param" type="string" />

    </cffunction>

    </cfinterface>

    TestInt.cfc

    <cfcomponent output="false" implements="ITest">

    <cffunction name="test" access="public" returntype="string" output="false">

    <cfreturn "hello world" />

    </cffunction>

    <cffunction name="test2" access="remote" returntype="string" output="false">

    <cfreturn "hello world 2" />

    </cffunction>

    </cfcomponent>

    index.cfm

    <cfscript>

    mycfc = createObject( "component", "TestInt" );

    </cfscript>

    <cfoutput>#mycfc.test()#</cfoutput>

    1 reply

    craigkaminskyCorrect answer
    Inspiring
    April 30, 2009

    vootmon,

    Question for you: What version of CF are you using?

    I created the following two CFCs on my machine.

    ITest.cfc

    <cfinterface displayName="ITest">

    <cffunction name="test" access="remote" output="false" returntype="string">

    <cfargument name="param" type="string" />

    </cffunction>

    </cfinterface>

    TestInt.cfc

    <cfcomponent output="false" implements="ITest">

    <cffunction name="test2" access="remote" returntype="string" output="false">

    <cfreturn "hello world" />

    </cffunction>

    </cfcomponent>

    index.cfm

    <cfscript>

    mycfc = createObject( "component", "TestInt" );

    </cfscript>

    <cfoutput>#mycfc.test2()#</cfoutput>

    When I run this in both CF 8.0.1 and Railo 3.1, I get the following error:

    Interfaces cannot have access="remote". On the value "public" is allowed.

    If I change the access in ITest.cfc to public, I get another error:

    TestInt.cfc does not implement the function test, which I did on purpose to test.

    After copying over/recreating the test function from the interface (with access="public" and the same parameter), it worked in CF 8 and Railo 3.1.

    This is the code that works:

    ITest.cfc

    <cfinterface displayName="ITest">

    <cffunction name="test" access="public" output="false" returntype="string">

    <cfargument name="param" type="string" />

    </cffunction>

    </cfinterface>

    TestInt.cfc

    <cfcomponent output="false" implements="ITest">

    <cffunction name="test" access="public" returntype="string" output="false">

    <cfreturn "hello world" />

    </cffunction>

    <cffunction name="test2" access="remote" returntype="string" output="false">

    <cfreturn "hello world 2" />

    </cffunction>

    </cfcomponent>

    index.cfm

    <cfscript>

    mycfc = createObject( "component", "TestInt" );

    </cfscript>

    <cfoutput>#mycfc.test()#</cfoutput>

    vootmonAuthor
    Participating Frequently
    May 1, 2009

    Thanks for the help!