page.cfc - "The request handler"

Which page to show

The primary focus of page.cfc is to handle the requested page. It parses out the requested page from either the url or the form scope and if neither of those exist, it calls the default layout sepecified in the framework's config.xml. The layout being requested is checked for the application's name as the first 'part' of the name, if it matches then we use it as it is. If not, then the first 'part' is checked to see if it is an extension that has asked to handle pages itself. Again, if so, the layout is left as is, however, a flag is raised that the request is being handled by an extension (instance.intercept is set to true). Finally, if neither of these are true, it is prepended with the applications name.

Once it has determined the layout being requested, it attempts to find out how to render it. To do this, it first queries its internal list of application pages, parsed from pages.xml. If no match can be found here, it looks in the application's controllers list, parsed from controllers.xml. Failing to match here it issues a global event 'onRequestPageletUndefined'. If the event is handled, the event system populates an IO object with the returned data and includes the information about which extension handled the event.

The final stage of this aspect of the process is to setup the various key values for page to carry out its role in the remainder of the rendering process. Information about which layout to use, the pagelets that will be required, etc or for controllers, which controller to use and where it can be found.

Let's Build

Once page.cfc has determined which page to build, it then becomes the primary controller for putting the page together. Control passes back to the root file, usually index.cfm, which immediately gets back in touch with page.cfc and asks for the layout to use.

The layout is essentially a cfm page that holds the basic structure of the rendered page, minus the actual content. The HTML framework that you wish to use for your page is all presented inside the layout. Regions within the template, where you want content to be placed are tagged. These regions are known as 'spaces' and can be filled with zero or more pagelets. A pagelet is simply a part of a page. CFRhino knows which pagelets to place in which space by using the data from pages.xml.