9 Replies Latest reply on Mar 11, 2013 11:23 AM by BKBK

    Can't get this.mappings to work

    jarviswabi

      Okay, I'm stumped enough to break a laptop.  I've been reading every post I can find today on how to setup per-Application mappings, and it just doesn't work.  Here's my situation:

       

      I have an existing site running on Linux under CF 9.0.1, and I had Mappings configured in CF Admin for 2 directories that I use in cfinclude tags throughout my CFMs and CFCs (so that those directories can remain above the webroot and not be exposed by Apache).  All that worked fine forever.

       

      Now I need to set up a second site with a separate set of directories, but I'm starting with a copy of the existing site's folders and then modifying the paths as needed.  For example, my first site is in /web/website, and my mappings are for "/cf-include" and "/cfc" mapped to "/web/website/cfc" and "/web/website/cf-include" in the Admin.  My webroot is "/web/website/htdocs", which is configured as my DocumentRoot in Apache.  For my second site, I created a new directory "/web/stwebsite" containing copies of the same directories, and created a VirtualHost in Apache with a DocumentRoot of "/web/stwebsite/htdocs".  I then added the following two mapping lines to my new Application.cfc (in that new directory), outside any of the functions :

       

       

      <cfcomponent displayname="Application" output="True" hint="Handle the application.">

       

      <cfset this.name="stapp">

      <cfset this.Sessionmanagement=False>

      <cfset this.ApplicationTimeout=CreateTimeSpan(1,0,0,0) />

      <cfset this.setClientCookies=False>

      <cfset this.mappings["/cf-include"]="/web/stwebsite/cf-include">

      <cfset this.mappings["/cfc"]="/web/stwebsite/cfc">

      ...

       

      I also made sure I had the Enable Per-App Settings checked in my CF Admin (it already was).  However, when I try to use those mappings, I get the one from the Admin and not the Application.cfc:

       

      <cfinclude template="/cf-include/sttest.cfm">

       

      I verified this by changing the content of that file in the two different directories and seeing which version showed up.

       

      So my question is, what's preventing the this.mappings settings from being used?  Am I wrong in understanding that I should be able to set those in the Application.cfc for the new site (which IS being used for that site, I verified that by changing what happens in the OnApplicationStart method) and have them supercede the Admin settings?  I also tried deleting the Mappings in the Admin, but that left all the cfincludes failing (saying the mapping didn't exist).  What am I missing?

        • 1. Re: Can't get this.mappings to work
          Ashish Todon Level 1

          Mapping use absolute path. I did it like this:-

           

          <cfset THIS.rootPath = GetDirectoryFromPath(GetCurrentTemplatePath()); /> // This gives me current directory of

                                                                                                                            // application.cfc i.e absolute path

                                                                                                                            // of my root

          <cfset THIS.mappings["/model"] = "#THIS.rootPath#/my_folder/Model"; /> // Then i append rest path to it

           

          • 2. Re: Can't get this.mappings to work
            BKBK Adobe Community Professional & MVP

            <cfset this.mappings["/cf-include"]="/web/stwebsite/cf-include">

            <cfset this.mappings["/cfc"]="/web/stwebsite/cfc">

            Potential problem: Including a hyphen in a directory name may cause problems when your site interacts with systems (like Java) where hyphens are disallowed in names. Replace cf-include with, say, cf_include.

            Problem: The right-hand side should be an absolute path instead. Hence, something like

             

            <cfset this.mappings["/cf_include"]=expandPath("/web/stwebsite/cf_include")>

            <cfset this.mappings["/cfc"]=expandPath("/web/stwebsite/cfc")>

            • 3. Re: Can't get this.mappings to work
              jarviswabi Level 1

              I did use absolute paths. This is Linux, so my absolute paths are "/web/stwebsite/cfc", etc.

              • 4. Re: Can't get this.mappings to work
                jarviswabi Level 1

                I'll try renaming that directory, but I also have an issue with the other directories that don't have hyphens in their names.  Do you think having one element like that would render the whole mappings structure useless?

                 

                As for the absolute paths, I already replied that those are my absolute paths because I'm on Linux.

                 

                Mike Simone

                • 5. Re: Can't get this.mappings to work
                  BKBK Adobe Community Professional & MVP

                  jarviswabi wrote:

                   

                  I'll try renaming that directory, but I also have an issue with the other directories that don't have hyphens in their names.  Do you think having one element like that would render the whole mappings structure useless?

                  No, I don't think so. In fact, given your explanation, I expect your original code to work. Yes, even with the hyphen!

                   

                  As for the absolute paths, I already replied that those are my absolute paths because I'm on Linux.

                  OK. Then ignore expandPath(). After all, it will just return the same absolute path.

                   

                  Let's do some tests. Does this work:

                   

                  <cfinclude template="/web/stwebsite/cf_include/sttest.cfm">

                   

                  Is your application file named Application.cfc, starting with capital A?

                  • 6. Re: Can't get this.mappings to work
                    BKBK Adobe Community Professional & MVP

                    Other tests worth doing are as follows. Make the following changes, only if temporarily. Change the application name to, say, stapp1. That will restart the application, ensuring no caches. Set sessionmanagement and setClientCookies to true. Remind ColdFusion that this.mappings is a structure, by doing

                     

                    <cfset this.mappings = structNew()>

                    <cfset this.mappings["/cf-include"]="/web/stwebsite/cf-include">

                    <cfset this.mappings["/cfc"]="/web/stwebsite/cfc">

                     

                    I am assuming you will do these tests one after the other, to find out which one has the required effect. Incidentally, did my expandPath suggestion work?

                    • 7. Re: Can't get this.mappings to work
                      jarviswabi Level 1

                      So frustrating.  I've tried all the suggestions provided so far to no avail.

                       

                       

                       

                      - Renamed the "cf-include" directory to "cfinclude" to eliminate the hyphen issue

                       

                      - Set the structure explicitly first

                       

                       

                       

                      I even tried this in my primary application (after deleting the mappings I had in the CF Admin) to see if it had any effect:

                       

                       

                       

                       

                       

                      I verified the Per-App flag is set, but it seems to be completely ignoring these instructions.

                      • 8. Re: Can't get this.mappings to work
                        Ashish Todon Level 1

                        Hi,

                            I just want to do some wild work.

                            1) Can you please dump THIS scope just after creation of mapping in Application.cfc.

                            2) simultaneously, dump THIS scope in your index.cfm page which get executed just after Application.cfc

                         

                        and check if mapping in dump(index.cfm) is same as you defined.

                         

                        I want to do this because might be mapping attribute in THIS scope get over written by some peace of code. I created same scenario on my side and i generated same problem.

                         

                        If both dumps are same please check permission of both of your files

                        • 9. Re: Can't get this.mappings to work
                          BKBK Adobe Community Professional & MVP

                          In which directory is the test CFM, that is, the CFM file containing the cfinclude tag? Please show us its directory structure right from the root. I suspect ColdFusion doesn't see the new Application.cfc file. To verify, set this.name to abracadabra. Then add the following line to the test CFM:

                           

                          Application name: <cfoutput>#application.ApplicationName#</cfoutput>

                           

                          What do you get?