Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Question regarding two application.cfc files.

Participant ,
Feb 03, 2010 Feb 03, 2010

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!

TOPICS
Advanced techniques
487
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 03, 2010 Feb 03, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 03, 2010 Feb 03, 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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 03, 2010 Feb 03, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 03, 2010 Feb 03, 2010
LATEST

Assuming a structure like this,

/root/myapp/Application.cfc
/root/myapp/dir1/blog/Application.cfc

and assuming there is a mapping for the root in the Administrator, then you would define the second Application file like this:

<cfcomponent extends="myapp.Application">

<! --- content --->

</cfcomponent>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources