4 Replies Latest reply on Feb 3, 2010 1:12 PM by BKBK

    Question regarding two application.cfc files.

    apocalipsis19

      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!

        • 1. Re: Question regarding two application.cfc files.
          Adam Cameron. Level 5

          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

          • 2. Re: Question regarding two application.cfc files.
            apocalipsis19 Level 1

            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!

            • 3. Re: Question regarding two application.cfc files.
              Adam Cameron. Level 5

              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

              • 4. Re: Question regarding two application.cfc files.
                BKBK Adobe Community Professional & MVP

                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>