Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Overriding argument in CFC from extended CFC

Status
Not open for further replies.

colddave

Programmer
Sep 15, 2007
1
GB
Hi

Im having a right nightmare trying to work this one out and have been trawling the net for hours.

- Ive got CFC called "BOB" with a function "dosomething"
- "dosomething" has a number of arguments he can take
- I then have another CFC "BOB" which extends the first "BOB"
- He also has a function "dosomething", and hes fine for extending "dosomething", but what about overiding

I want my primary "dosomething" to have one of his arguments changed by the extender "dosomething".

So whenever my extender says 'hey "dosomething" I actually want your arguments.id to be 3' the primary function gets the message.

Im sure this is possible, and ive seen some articles on calling it with "super", but no working examples.

Can anyone supply the code I can use to change this argument?

Many thanks in advance

Dave

 
Code:
<!--- 
	/testPage.cfm  (MX7)
	
	creating an instance of both the primary and 
	extender component only to demonstrate the 
	results are different
--->
<cfset primaryBob = createObject("component", "BOB").init()>
<cfset extenderBob = createObject("component", "BOBExt").init()>

<!--- compare the results --->
Results from primary component:<br>
<cfdump var="#primaryBob.dosomething(id=123,description='abc')#">
Results from extender component:<br>
<cfdump var="#extenderBob.dosomething(id=123,description='abc')#">

<!--- /BOB.cfc ---->
<cfcomponent hint="primary component">
	<cffunction name="init" returntype="BOB">
		<cfreturn this>
	</cffunction>

	<cffunction name="dosomething" returntype="struct">
		<cfargument name="id" type="numeric" required="true">
		<cfargument name="description" type="string" required="true">
		<!--- echo the arguments --->
		<cfreturn duplicate(arguments)>
	</cffunction>
</cfcomponent>

<!--- /BOBExt.cfc ---->
<cfcomponent extends="BOB" hint="extender component">
	<cffunction name="init" returntype="BOBExt">
		<cfset super.init()>
		<cfreturn this>
	</cffunction>

	<cffunction name="dosomething" returntype="struct">
		<cfargument name="id" type="numeric" required="true">
		<cfargument name="description" type="string" required="true">
		<!--- changing argument.id to "3" --->
		<cfset var results = super.dosomething(id=3, description=arguments.description)>	
		<cfreturn results>
	</cffunction>
	
</cfcomponent>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top