从a调用组件b的init方法

时间:2014-08-02 10:19:36

标签: coldfusion

在我的一个组件abc.cfc中,我正在扩展另一个组件:xyz.cfc。组件xyz.cfc有一个init()方法,它期望:datasource,username,password。

在我的应用程序中,我正在使用它:

<cfset this.mappings = structNew() />
<cfset this.mappings["/com"] = getDirectoryFromPath(getCurrentTemplatePath()) & "com/">
<cfset Application.tools = new com.abc()>

现在在abc.cfc中我正在做以下事情:

<cfcomponent hint="The File which acces the Information about the Detail" extends="xyz">

和xyz.cfc具有以下功能:

<cffunction name="init" access="public" output="No" returntype="mysql" hint="Initializes the component">
        <cfargument name="datasource" required="Yes" type="string" />
        <cfargument name="username" required="Yes" type="string" />
        <cfargument name="password" required="Yes" type="string" />

        <cfscript>
            variables.instance = structNew();
            setDatasource(argumentcollection=arguments); // set datasource information
            clearCache(); // create cache struct

            variables.instance.trim = true;

            return this;
        </cfscript>
    </cffunction>

产生如下错误:

 The DATASOURCE parameter to the INIT function is required but was not passed in.   The error occurred in C:/ColdFusion11/cfusion/wwwroot/project1/admin/Application.cfc: line 28

1 个答案:

答案 0 :(得分:4)

您只需在构造函数调用中传递参数值:

<cfset Application.tools = new com.abc(datasource=datasource, etc)>