8 Replies Latest reply: Nov 20, 2011 11:39 AM by -==cfSearching==- RSS

    application.cfc vs application.cfm

    mega_L Community Member

      My CF version is 8 but since I came to this company and inherrited the codes, it looks like previous programmer did not use much of CF8 features.

      I started to take advantage of CF8 features including cfc. One thing that I notice is all the existing apps. are using application.cfm and none uses application.cfc

       

      I have sort of a portal web application where under this app. there are a bunch of different applications

      The portal application has application.cfm that is encrypted so whenever I create a new app, I created my own application.cfm each with a different name set on the cfapplication tag

      So it sort of to look like this:

       

      Portal app

        application.cfm (encrypted)

           application_1

             application.cfm

       

           application_2

            application.cfm

        

           application_3

             application.cfm

       

      I want to experience the CF8 application.cfc and from what I read, if I use application.cfc I can't use application.cfm because application.cfc replacing application.cfm and OnrequestEnd.cfm

      when application.cfc is present both application.cfm and OnrequestEnd.cfm are going to be ignored.

      My concern is, when I start creating application.cfc on my sub application, will the application.cfc ignoring Portal's application.cfm (the encrypted application.cfm) eventhough it is

      on a much higher up in the directory tree?

       

      So can i do the following without messing up the whole application?

      Portal app

        application.cfm (encrypted)

           application_1

             application.cfm

       

           application_2

            application.cfm

        

           application_3

             application.cfm

       

           application_4

             application.cfc  <<< (?)

        • 1. Re: application.cfc vs application.cfm
          Dan Bracuk Community Member

          What happened when you tried it?

          • 2. Re: application.cfc vs application.cfm
            -==cfSearching==- Community Member

            when I start creating application.cfc on my sub application, will the application.cfc ignoring Portal's application.cfm (the encrypted application.cfm) eventhough it is on a much higher up in the directory tree?

             

            Yes. In that respect, it is no different than an Application.cfm file. CF starts searching within the directory of the requested script for the first Application.cfc it finds (or if none exists, Application.cfm). As soon as it finds one, CF processes it and stops searching. So it is not even aware of any application files higher up in the directory tree.  

             

            You can find more details about how CF processes application.cfc/cfm files in  the documentation.  The example at the bottom of the page describes an application structure very similar to yours.

            • 3. Re: application.cfc vs application.cfm
              mega_L Community Member

              Would it matter if I created application.CFC on my subfolder application and then include the application.CFM from the main app. using cfinclude (see below)

              The reason I'm asking is, I'm pretty sure some variables are set in the Main's application.cfm and also some java codes are written in there. All of them are encrypted. I'm afraid in order for my new app to work properly I may need the main application.cfm. So it'll be prefect if I can include the Application.cfm from the main app in my new application.cfc

               

              I can't test it in my local machine. When I tried it I got a bunch of java errors.

               

               

              This is my application.cfc:

              <cfinclude template="/Application.cfm">

               

               

              • 4. Re: application.cfc vs application.cfm
                -==cfSearching==- Community Member

                Yes, that would make a difference.  I have never cfincluded an application.cfm file from another appplication file. So I am really not sure what the results would be.  I imagine there is no technical reason you could not do that inside one of the Application.cfc methods, but without knowing what the main file does it would be tough to know where to include it or even what the results would be.  What variables/scopes does it affect? Also, what do the sub folder's application files do other than including the one from the parent directory?

                • 5. Re: application.cfc vs application.cfm
                  insuractive Community Member

                  Typically, if you are using your inner application.cfm file just for its built-in OnRequestStart() functionality and not actually defining a new application name, you can include other application.cfm files to your hearts content.  I'm assuming that application.cfc's work in a similar manner.

                   

                  BTW - not sure if you saw Ben Nadel's article on extended functionality in pre-packaged encrypted application.cfm files, but it seemed to be appropriate to your problem so I thought I would include it:

                   

                  http://www.bennadel.com/blog/1322-Extending-Encrypted-ColdFusion-Application-cfm-Functiona lity.htm

                  • 6. Re: application.cfc vs application.cfm
                    insuractive Community Member

                    You might be able to get it working if you leave off the NAME property of the application.cfc file (not sure if CF will throw an validation error because of that though).  Because you're not sure exactly what's in your original application.cfm, you may want to consider testing to see if you can include it by creating a blank application.cfm in the directory you are testing and trying to include your site's top application.cfm from there.  If it works, you know that its not the directory path that's an issue.  If it doesn't work, there may be some code in the top-level application.cfm that requires that it executes in a specific directory (though this is probably unlikely due to the nature of how application.cfm files are executed by CF).

                     

                    I think they may even be tools that will allow you to decrypt your template, provided that you have legal permission (EULA, DCMA, etc) to actually do that.

                    • 7. Re: application.cfc vs application.cfm
                      BKBK MVP

                      mega_L wrote:

                       

                      Would it matter if I created application.CFC on my subfolder application and then include the application.CFM from the main app. using cfinclude (see below)

                      The reason I'm asking is, I'm pretty sure some variables are set in the Main's application.cfm and also some java codes are written in there. All of them are encrypted. I'm afraid in order for my new app to work properly I may need the main application.cfm. So it'll be prefect if I can include the Application.cfm from the main app in my new application.cfc

                       

                      I can't test it in my local machine. When I tried it I got a bunch of java errors.

                       

                       

                      This is my application.cfc:

                       

                      <cfinclude template="/Application.cfm">

                       

                      That would in fact be my suggestion. Include Application.cfm via the onRequestStart event of Application.cfc (note capital A). Here follows an example

                       

                      <cfcomponent displayname="CFTests Application file">

                          <cfscript>

                              this.name = "bkbk_app";

                              this.applicationTimeout = "#createTimespan(1,0,0,0)#";

                              this.loginStorage = "session";

                              this.sessionManagement = "true";

                              this.sessionTimeout = "#createTimeSpan(0,0,20,0)#";

                              this.setClientCookies = "yes";

                              this.scriptProtect = "yes";

                          </cfscript>

                       

                      <cffunction name="onApplicationStart" returntype="boolean">

                      <cfreturn true>

                      </cffunction>

                       

                      <cffunction name="onSessionStart">

                      </cffunction>

                       

                      <cffunction name="onRequestStart">

                      <cfargument name = "targetPage" type="String" required="yes">

                          <cfinclude  template="/Application.cfm">

                      </cffunction>

                       

                      <cffunction name="onRequestEnd">

                      <cfargument type="String" name = "targetTemplate" required="yes">

                      </cffunction>

                       

                      <cffunction name="onSessionEnd">

                      <cfargument name = "SessionScope" required="yes">

                      <cfargument name = "AppScope" required="yes">

                          <cflog file="#This.Name#" type="Information" text="Session: #arguments.SessionScope.sessionid# ended">

                      </cffunction>

                       

                      <cffunction name="onApplicationEnd">

                      <cfargument name="ApplicationScope" required="yes">  

                          <cflog file="#This.Name#" type="Information" text="Application #ApplicationScope.applicationname# ended">

                      </cffunction>

                      </cfcomponent>

                      • 8. Re: application.cfc vs application.cfm
                        -==cfSearching==- Community Member

                        Because you're not sure exactly what's in your original application.cfm, you may want to consider testing to see if you can include it by creating a blank application.cfm in the directory you are testing and trying to include your site's top application.cfm from there.

                        Yeah, I did not think there would be any technical problem with including a file.  But without knowing what it does, or what scopes it affects, I could not say definitively where it belongs. OnRequestStart is certainly the most logicial guess.  But again .. knowing so little about it, I think testing it out would be a wise idea.