我有两个CFC,它们是具有DAO功能的Bean。我已经在child cfc扩展父级的地方设置了继承。继承的CFC不填充
两个物体具有相同的结构;函数:初始化,读取等等和属性:ID等
当我创建子对象时,我传递一个ID,读取数据,获取父项的外键parentID,然后Super.init( )用适当的参数调用。
我意外的结果是: 子对象的ID和parentID都是相同的,并且是返回对象时的parentID值。超级调用后,孩子的变量.ID被覆盖。我假设变量作用域可以被两者访问,所以当父设置变量.ID时,它会覆盖子变量.ID。如果没有对ID进行不同的命名,这可以避免吗
父对象的读取功能似乎不会执行。例如,如果我重命名父节点读取函数'read2',则该函数执行。我也怀疑这些函数驻留在一个共享范围内,因此childs读取函数正在执行。
是否有任何方法来维护相同的cfc结构并使该功能按预期工作?
在此先感谢。
<cfcomponent accessors="true" extends="Custom" output="false">
<cfproperty name="ID" type="numeric" />
<cfproperty name="listID" type="numeric" />
<cfproperty name="customfieldID" type="numeric" />
<cfscript>
variables.dsn = '';
</cfscript>
<cffunction name="init" access="public" output="false" returntype="ListCustom">
<cfargument name="dsn" type="string" required="true" />
<cfargument name="ID" type="numeric" required="true" />
<cfargument name="listID" type="numeric" required="false" default="0" />
<cfargument name="customFieldID" type="numeric" required="false" default="0" />
<cfscript>
variables.dsn = arguments.dsn;
variables.ID = arguments.ID;
variables.listID = arguments.listID;
variables.customFieldID = arguments.customFieldID;
if (variables.ID){
read();
if (variables.customFieldID){
Super.init(dsn=variables.dsn,ID=variables.customfieldID);
}
}
</cfscript>
<cfreturn this />
</cffunction>
<cffunction name="read" access="private" output="false" returntype="void">
<cfquery name="local.q" datasource="#variables.dsn#">
SELECT customfieldID, listID
FROM listCustomFields
WHERE ID = <cfqueryparam value="#variables.ID#" cfsqltype="cf_sql_integer">
</cfquery>
<cfif local.q.recordcount>
<cfset variables.listID = local.q.listID />
<cfset variables.customFieldID = local.q.customFieldID />
</cfif>
</cffunction>
<cfcomponent accessors="true" output="false">
<cfproperty name="ID" type="numeric" />
<cfproperty name="fieldName" type="string" />
<cfscript>
variables.dsn = '';
</cfscript>
<cffunction name="init" access="public" output="false" returntype="Custom">
<cfargument name="dsn" type="string" required="true" />
<cfargument name="ID" type="numeric" required="true" />
<cfargument name="fieldName" type="string" required="false" default="" />
<cfscript>
variables.dsn = arguments.dsn;
variables.ID = arguments.ID;
variables.fieldName = arguments.fieldName;
if (variables.ID){
read();
}
</cfscript>
<cfreturn this />
</cffunction>
<cffunction name="read" access="private" output="false" returntype="void">
<cfquery name="local.q" datasource="#variables.dsn#">
SELECT fieldName
FROM CustomField
WHERE ID = <cfqueryparam value="#variables.ID#" cfsqltype="cf_sql_integer">
</cfquery>
<cfif local.q.recordcount>
<cfset variables.fieldName = local.q.fieldName />
</cfif>
</cffunction>
你能分享一些代码吗?另外,在父母/子女关系中,我不确定是否有孩子延长父母的路要走。两者都可以扩展一个“基础”对象,但是不确定孩子是否延伸父母是一条路。 –