Our Forums are now closed. Please go to our Google Mailing List for help. This site will remain open for historical purposes.
ColdBox Framework Forums Home | Profile | Search | Login | RSS

 pdf Print PDF   Previous Page  Page: 1   Next Page

Thread: Renderer locateView "bug"
Created on: 06/03/10 06:12 AM Replies: 0
MrNil


Joined: 05/18/10
Posts: 2
Renderer locateView "bug"
06/03/10 6:12 AM

This is a long running issue that we've had with the renderer.

In most of our applications, due to the way we structure them, we have ColdFusion mappings for the main site as well as to external views.

When you build up a view path using a mapping rather than a physical folder in the top level of a view expandPath will throw you a whammy... (See my blog post here from ages ago for why : http://nil.checksite.co.uk/index.cfm/2008/9/11/getdirectoryfrommapping-function-to-solve-a-problem-with-expandpath)

coldbox.system.plugins.Renderer.locateView() will generate a path using the mapping, which is correct, but when you call expandPath() on this path it will return the name of the template currently being called. When you then call FileExists() you get a "true" returned, because its looking at the current template and not the view. This means that external views are never returned from locateView()

We had just been hacking some code in to handle our specific situation, but I've just rewritten it to be more generic and thought I would attempt to explain the problem and post my solution (in the vain hope that it ends up in the core code and I don't have to hack it every time we download a new version of ColdBox ;) ).

Bascially, rather than checking to see if the file exists I check to make sure that the template name at the end of the physical path is the same as the one at the end of the relational/mapping path.

Here's the code. It should make perfect sense. :)

<!--- locateView --->

   <cffunction name="locateView" output="false" access="private" returntype="any" hint="Locate the view to render">

      <cfargument name="view"       type="any"       required="true"    hint="The view name" >

      <cfscript>

         // Default path is the conventions
         var viewPath    = "/#instance.appMapping#/#instance.viewsConvention#/#arguments.view#";

         var extViewPath = "#instance.viewsExternalLocation#/#arguments.view#";

         var viewPathPhysical = expandPath(viewPath & ".cfm");

         var extViewPathPhysical = expandPath(extViewPath & ".cfm");

         var slash = iif(findnocase("window",server.os.name),de('\'),de('/'));



         // Check if view does not exists in Conventions
         // ExpandPath bug fix
         if ( ListLast(viewPathPhysical,slash) NEQ ListLast(viewPath&".cfm","/") AND fileExists(extViewPathPhysical) )

         {

            return extViewPath;

         }



         return viewPath;

      </cfscript>

   </cffunction>


Regards

Stephen
Link | Top | Bottom

Galleon Forums V1.7.008 was created by Raymond Camden