Skip to main content
Inspiring
February 3, 2010
Question

Question regarding two application.cfc files.

  • February 3, 2010
  • 1 reply
  • 550 views

Hi Community!

I have a coldfusion application and just installed Mango Blog. Now I am updating some pages inside the blog folder. The problem is that when I try to use my existing header my files inside the blog folder do not recognize it. It is attempting to use application variables from my main application.cfc.

So the whole thing is that I have an application.cfc on my /root/myapp/ directory and Mango has one on blog/. How can I make my main application variables be initialized inside the blog folder that seem to have another set of application variables.

Thanks!

This topic has been closed for replies.

1 reply

Inspiring
February 3, 2010

Normally when one wants one class (CFC in CF's case) to inherit the behaviour of another class, then one uses EXTENDS on the subclass.  Equally, in circumstances in which subclass methods need to replicate whatever the super class' equivalent method does before doing its own specialisation, one calls super.methodName() in the subclass' equivalent method, before doing whatever else it needs to do.

Same with Application.cfc

--

Adam

Inspiring
February 3, 2010

Hmmm, that makes sense Adam. I have never used that feature before. How do I refer to application.cfc inside the extend? I have tried a couple of  things and it says that the class was not found. My main application.cfc is two levels up the blog directory....

Thanks!

Inspiring
February 3, 2010

Something like this:

<!--- parent.cfc --->
<cfcomponent>

    <cffunction name="f">
    </cffunction>
   
</cfcomponent>


<!--- child.cfc --->
<cfcomponent extends="path.to.parent">

    <cffunction name="f">
        <cfset something = super.f()>
    </cffunction>
   
</cfcomponent>


Obviously they'll both be Application.cfc files though.  The path you need for the extends is the dotted path from the root of the site (or the root of the mapping the file is in). The easiest way to find the path (as CF sees it) is to rename the Application.cfc you want to extend to app.cfc and then browse to the file.  The path is displayed at the top of the ensuing auto-generated documentation file.  One needs to rename the file as one cannot browse directly to an Application.cfc file.  Obviously rename it back afterwards.

Make sense?

--

Adam