views:

263

answers:

2

Let's say I have the following component called 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>

and I want to extend base in another component called Admin:

<cfcomponent output="false" extends="Base">
</cfcomponent>

Now within my application if I do the following when creating the object:

<cfset obj = createobject("component", "Admin").init()>
<cfdump var="#obj.getmeta()#">

The metadata I get back tells me that the name of the component is Admin and it's extending my Base component. That's all good, but I don't want to have to call the init() method explicitly when creating the object.

I would be nice if I could do something like this in my Base component:

<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>

However then the metadata returned by the getmeta() method telling me that the component name is Base even though it's still being extended. Any thoughts on how to accomplish this?

A: 

Is there a reason you don't want to call init in each extending cfc?

<cfcomponent output="false" extends="Base">
    <cfset super.init()>

</cfcomponent>

That seems to populate the metadata like you want.

Soldarnal
+1  A: 

I'm not 100% sure what you are after, but ColdFusion 8 added the getComponentMetaData() function that instead of requiring an instantiated CFC, takes a dot notation path to the CFC. You should be able to get the path from Admin which you can pass to getComponentMetaData() without calling the init() on Base.

ColdFusion LiveDoc: getComponentMetaData()

Adrocknaphobia