假设我有以下组件Base:
<cfcomponent output="false">
<cffunction name="init" access="public" returntype="Any" output="false">
<cfset variables.metadata = getmetadata(this)>
<cfreturn this>
</cffunction>
<cffunction name="getmeta" access="public" returntype="Any" output="false">
<cfreturn variables.metadata>
</cffunction>
</cfcomponent>
我想在另一个名为的组件中扩展基础Admin:
<cfcomponent output="false" extends="Base">
</cfcomponent>
现在在我的应用程序中,如果我在创建对象时执行以下操作:
<cfset obj = createobject("component", "Admin").init()>
<cfdump var="#obj.getmeta()#">
我得到的元数据告诉我该组件的名称是Admin它正在扩展我的Base成分。一切都很好,但我不想打电话给init()创建对象时显式方法。
如果我能在我的工作中做这样的事情,我会很高兴Base成分:
<cfcomponent output="false">
<cfset init()>
<cffunction name="init" access="public" returntype="Any" output="false">
<cfset variables.metadata = getmetadata(this)>
<cfreturn this>
</cffunction>
<cffunction name="getmeta" access="public" returntype="Any" output="false">
<cfreturn variables.metadata>
</cffunction>
</cfcomponent>
然而 getmeta() 方法返回的元数据告诉我组件名称是Base尽管它仍在延长。关于如何实现这一目标有什么想法吗?
您是否不想在每个扩展 cfc 中调用 init ?
<cfcomponent output="false" extends="Base">
<cfset super.init()>
</cfcomponent>
这似乎按照您想要的方式填充元数据。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)