root/codedepot/trunk/projects/ColdBox-3.0-Upgrader/AppTemplate/config/routes.cfm @ 2077

Revision 2077, 6.2 kB (checked in by lmajano, 4 years ago)

The start of the groovy 3.0 upgrader

Line 
1<!--- -------------------------------------------
2        Configure your setup here...
3        This file is executed directly in the ses interceptor spawned from Adam Fortuna's ColdCourse.
4        Therefore, ALL methods related to a plugin/interceptor/handler are available, you
5        can use getSetting(), getController(), etc....
6       
7        I actually ENCOURAGE you to use the getSetting() for tier detection.
8       
9        All credits to Adam Fortuna, Rob Cameron & Per Djurner of Coldfusion On Wheels
10        for innovating this routing method in Coldfusion.
11       
12NOTE: The interceptor will create a new setting called: sesBaseURL with this value
13        so it can be used by your application for any HTML base tags or relocations.
14        The interceptor will also create the setting: htmlBaseURL so you can use in your
15        <base> html tags, this is the same as the baseURL without the index.cfm if used.
16        Else, htmlBaseURL and sesBaseURL should be the same.
17       
18-------------------------------------------- --->
19
20<!---
21        Do you want SES Interception to be on or off?
22--->
23<cfset setEnabled(true)>
24
25<!---
26        This determines if non-ses urls should be routed back to ses.
27        In other words, if someone goes to http://localhost/index.cfm?event=home.main
28        should we redirect (301, permanantly moved) to the ses url:
29        http://localhost/index.cfm/home/main ?
30
31        This will also make sure that any trailing index pages get redirected as well, so
32        if you go to http://localhost/home/index it would redirect to http://localhost/home
33        if index is your framework action default.
34
35        For SEO purposes it's always best to have one URL for everything, not 3!
36--->
37<cfset setUniqueURLs(false)>
38
39<!---
40        The Base URL for your site. This will only be used for forwarding requests if
41        UniqueURLs is enabled and for creating the new Application settings:
42       
43        - sesBaseURL
44        - htmlBaseURL
45   
46    If you want your URLs to look like http://localhost/handler/action then you should
47    put "http://localhost" here. For this option you'll need .htaccess or isapi rewrite support.
48   
49    If you want your URLs to look more like http://localhost/index.cfm/handler/action, then
50    put "http://localhost/index.cfm" here. No additional setup is required to use this setting.
51
52        You can place any tier detection within this section if needed.
53       
54        NOTE: The interceptor will create a new setting called: sesBaseURL with this value
55        so it can be used by your application for any HTML base tags or relocations.
56        The interceptor will also create the setting: htmlBaseURL so you can use in your
57        <base> html tags, this is the same as the baseURL without the index.cfm if used.
58        Else, htmlBaseURL and sesBaseURL should be the same.
59--->
60<cfif len(getSetting("AppMapping")) lte 1>
61        <cfset setBaseURL("http://#cgi.HTTP_HOST#/index.cfm")>
62<cfelse>
63        <cfset setBaseURL("http://#cgi.HTTP_HOST#/#getSetting('AppMapping')#/index.cfm")>
64</cfif>
65
66<!--- -------------------------------------------
67        Add your Courses here...
68        The syntax of these is the same as that of Coldfusion on Wheels, and similar to Ruby
69        on Rails.  The idea is that the number of variables in a URL will be the first indicator
70        of which course to use.
71       
72        ColdBox 2.6 added an extension to the :variable so you can declare a numerical value:
73        Ex: handler/action/:id-numeric Will match if the id position is numeric
74        Ex: handler/action/:id Will match any alphanumeric position.
75        This extends the custom courses to distinguish between alphanumeric and numeric placeholders.
76       
77        ColdBox also introduces the Optional Variable Place Holders by adding a "?" at the end of the var name
78        Ex: handler/:action?
79        The action? denotes that this is an optional variable, so ColdBox will construct two routes for you
80        handler/:action and handler/ in that order of preference.  This is great for creating a single route
81        for multiple optional parameters.
82        Ex: /blog/:year/:month?/:day? ColdBox will then be creating the following routes for you.
83        /blog/:year/:month/:day
84        /blog/:year/:month
85        /blog/:year
86       
87        How cool is that. Just remember that there cannot be required variable placeholders after optional ones.
88       
89        Here's the general setup:
90        <cfset addCourse(       pattern="handler/action/:id",   # Set the pattern
91                                                handler="handler_name",                 # Set the handler
92                                                action="action_name" )>                 # Set the action
93                                               
94        Notice how the "pattern" argument has three parts. In this case if a request comes in that starts with
95        "/handler/action", such as "http://localhost/handler/action/oneOtherItem", this course will match.
96        The "oneOtherItem" variable will be set to a URL variable with the name ID
97        <cfset url["ID"] = "oneOtherItem"> before then routing to the "handler_name" handler and the
98        "action_name" action. This would be the same as the URL
99        http://localhost/index.cfm?event=handler_name.action_name&id=oneOtherItem
100       
101        It's important to remember that courses are evaulauted in order and go with the first one that matches.
102        For instance if you have a course for /:handler/:action/:username, and another course later for
103        /:handler/:action/:id, then the second course will NEVER be run. If instead you change your first
104        course to something more generic such as /user/:action/:username, and specify (handler="user") as
105        a second paramter, then only URLs that start with /user will qualify for having the thrid argument of
106        username, while everywhere else will use a third argument of ID.
107       
108        By the way, what's with the : syntax?  In the Ruby programming language, any variable
109        starting with a : is a symbol. Symbols are just like strings but they always point to
110        the same place in memory and are therefore more efficient.  They don't work that way
111        here in ColdFusion, but they make a good variable marker without worrying about where
112        to put quotes and stuff
113       
114        Examples:
115        <cfset addCourse(       pattern="entry/:year-numeric/:month-numeric/:day-numeric",
116                                                handler="blog",
117                                                action="entry" )>
118        <cfset addCourse(       pattern="entry/:year-numeric/:month/:day-numeric",
119                                                handler="blog",
120                                                action="entry" )>
121        <cfset addCourse(       pattern="profile/view/:username",
122                                                handler="profile",
123                                                action="view" )>       
124        <cfset addCourse(":handler/:action?/:id?")>             
125-------------------------------------------- --->
126                                       
127<!--- CUSTOM COURSES GO HERE (they will be checked in order) --->
128
129
130<!--- STANDARD COLDBOX COURSES, DO NOT MODIFY UNLESS YOU DON'T LIKE THEM --->
131<cfset addCourse(":handler/:action?/:id?")>
Note: See TracBrowser for help on using the browser.