Routing question

41 views
Skip to first unread message

raulriera

unread,
Apr 3, 2009, 4:17:15 PM4/3/09
to ColdFusion on Wheels
Hi,

I may be trying to bend the rules here, but I was wondering if anyone
knew how to do this

routes.cfm

<cfset addRoute(name="userContracts", pattern="users/[userId]/
contracts/[action]/[key]", controller="contracts")>
<cfset addRoute(name="userContracts", pattern="users/[userId]/
contracts/[action]", controller="contracts")>
<cfset addRoute(name="userContracts", pattern="users/[userId]/
contracts/", controller="contracts", action="index")>

I can do

linkTo(route="userContracts") just fine, but the link instead of beign

users/1/contracts

becomes

users/contracts

Chris Peters

unread,
Apr 3, 2009, 5:06:47 PM4/3/09
to cfwh...@googlegroups.com
I've been having some troubles with routes myself.

If I do something like this, calls to linkTo() fail:

<cfset addRoute(name="adminSettings", pattern="admin/settings/[action]", controller="AdminSettings", action="index")>
<cfset addRoute(name="adminSettingsMain", pattern="admin/settings", controller="AdminSettings", action="index")>

raulriera

unread,
Apr 3, 2009, 8:01:13 PM4/3/09
to ColdFusion on Wheels
How are you handling that /admin on your app? I am wondering how to do
that as well (if that is the "best" way to go anyway)

Chris Peters

unread,
Apr 4, 2009, 1:18:13 AM4/4/09
to cfwh...@googlegroups.com
I've decided to just go with putting an entire copy of Wheels in the admin folder. It's not as important to have the full rewriting, and my admin section is going to be rather large so as to be too much for one single admin controller.

I'm going to be playing around with virtual directories in Apache to see if I can at least get the admin area to share the same config and models as the base app. Will let you know how that works out.

raulriera

unread,
Apr 4, 2009, 5:31:37 AM4/4/09
to ColdFusion on Wheels
Ohhhhh that would be too sweet actually, I am struggling right now on
how to manage this... (too much used to the old ways) If you find
anything please share :)

raulriera

unread,
Apr 4, 2009, 6:07:22 AM4/4/09
to ColdFusion on Wheels
Reading the docs I found out the answer to my question up top
(including the userId to the linkTo is the way to do it) but now I
have a new problem, if I just want to do this

<cfset addRoute(name="home", pattern="", controller="wheels",
action="congratulations")>
<cfset addRoute(name="userProfile", pattern="users/[login]",
controller="users", action="show")>

How do I do this without having to hardcode EACH action of the Users
controller in the routes as well? corrently all actions but the
"index" action will call this "userProfile" route. The workaround is
to manually add each action of the controller to the routes.cfm but
this seems like a big pain.

Am I doing something wrong?

rip747

unread,
Apr 4, 2009, 8:48:16 AM4/4/09
to ColdFusion on Wheels
well once we get to 1.0, it might be time to give the routing engine
an overhaul and see what else we can add to it.

i think to solve your problem raul, we will need to add some sort of
restful code to the routing engine.

there might already be some code out there to do this, i'll have to
look around.

adding support for namespaces could be the answer to what chris is
doing.

an example would be:

<cfset addRoute(namespace="admin", pattern="", controller="settings",
action="index")>

now the routing engine would automatically prepend "admin" to the
controller like so "admin/settings". then all we need to do is figure
out a way to get the models, views, and helpers to map. if anyone
knows ruby, check so see how rails is doing this and maybe we could
port the code.

just a thought.

i also found another routing engine on github:

http://github.com/shaynesweeney/coldfusion-routes/tree/master

he added support for regex and udfs into the engine.

raulriera

unread,
Apr 4, 2009, 3:26:08 PM4/4/09
to ColdFusion on Wheels
Although an overhaul will help, all of that can be done with the
current solution (with a little bit of time to copy and paste lines
like crazy into the routes.cfm). In the mean while I am going to add
all "manual" routes to the routes.cfm via the Scaffold.cfc

ch...@clearcrystalmedia.com

unread,
Apr 4, 2009, 4:59:40 PM4/4/09
to ColdFusion on Wheels
I tried creating an alias to the root wheels, config, models, and
plugin folders, but unfortunately ColdFusion reads the aliases as
files and not folders.

I ran these lines of code from my admin folder:
<cfdirectory action="list" directory="/path/to/admin"
name="directory">
<cfdump var="#directory#"><cfabort>

Unfortunately, the line for the aliased wheels folder looks like this:

ATTRIBUTES DATELASTMODIFIED DIRECTORY MODE NAME SIZE
TYPE
[empty string] 04/04/2009 04:52:15 PM /path/to/admin [empty
string] wheels 0 File

I wonder if the same thing happens on Linux or Windows.

ch...@clearcrystalmedia.com

unread,
Apr 4, 2009, 5:00:32 PM4/4/09
to ColdFusion on Wheels
Forgot to mention that the aliases are OS X aliases.

raulriera

unread,
Apr 4, 2009, 9:04:04 PM4/4/09
to ColdFusion on Wheels
here is what I think are the possible scenarios for an "admin" area:

1 - Have 2 separate wheels applications with duplication all over the
place.
2 - Have 2 separate wheels applications where the "site" consumes the
"admin" controllers via cfhttp
3 - Have everything in one application where you render a different
view and layout depending if the URL contrains "/admin/[controller]/
[action]/etc" or not

I think you are going with the first one and trying to not duplicate
everything right?

Chris Peters

unread,
Apr 4, 2009, 10:32:49 PM4/4/09
to cfwh...@googlegroups.com
The "main" app is a CMS where the URL structure is 100% defined in the database. That messes up the "regular" Wheels routes pretty bad, so I was trying to get the admin stuff out of that system.

I was able to hard code controller/action stuff in routes.cfm to a certain point (your option #3 below), but it stopped working in certain cases, and it was going to get really bad after a certain point of complexity.

I may need to try #2 or settle for #1. #2 actually feels a little uglier to me, but I'm sure that's a matter of opinion. :)

raulriera

unread,
Apr 5, 2009, 2:25:24 AM4/5/09
to ColdFusion on Wheels
I was hoping you will prove me wrong :( I don't like either of those
scenarios haha... I am going with "4" for now:

4 - Everything in one place, but the "admin" is "Users.cfc" and the
"site" is either "Pages.cfc" or another Controller that will make
sense, like "Articles.cfc" is the "admin" controller and "News.cfc" is
the "site" controller.

Chris Peters

unread,
Apr 5, 2009, 9:24:00 AM4/5/09
to cfwh...@googlegroups.com
I kind of like that. I could have a Site.cfc that preps public-facing functionality and an Admin.cfc that preps back office stuff (like forcing the user to log in). Depending on what the controller is meant to do, it could extend the appropriate CFC.

Chris Peters

unread,
Apr 5, 2009, 9:35:47 AM4/5/09
to cfwh...@googlegroups.com
Also, I think I may need to go back to the drawing board on the database-driven CMS. Maybe custom routes aren't the best way to go about it? I think I will poke around in the dark corners of the events folder, like onmissingtemplate.cfm and onerror.cfm.

rip747

unread,
Apr 5, 2009, 1:48:05 PM4/5/09
to ColdFusion on Wheels
chris,

if i'm following you correctly, you want to different wheels
application to be able to share some of the same components.

I think you approach with having the admin section and the cms
frontend in separate applications is a good idea. That sort of setup
will allow you to make the admin application use an SSL cert for
better seurity. I know this could probably be accomplished with a
filter checking against getpagecontext().getrequest().issecure().

As for reusing the components from the cms frontend in the admin
application, you could just create an application based mapping to the
cms frontend application and then just extend those component in your
admin application.

If any of this is off base then just tell me and shut up. :)



On Apr 5, 9:35 am, Chris Peters <ch...@clearcrystalmedia.com> wrote:
> Also, I think I may need to go back to the drawing board on the
> database-driven CMS. Maybe custom routes aren't the best way to go about it?
> I think I will poke around in the dark corners of the events folder, like
> onmissingtemplate.cfm and onerror.cfm.
>
> On Sun, Apr 5, 2009 at 9:24 AM, Chris Peters <ch...@clearcrystalmedia.com>wrote:
>
> > I kind of like that. I could have a Site.cfc that preps public-facing
> > functionality and an Admin.cfc that preps back office stuff (like forcing
> > the user to log in). Depending on what the controller is meant to do, it
> > could extend the appropriate CFC.
>

Chris Peters

unread,
Apr 5, 2009, 4:19:17 PM4/5/09
to cfwh...@googlegroups.com
No, that's useful Tony. Let me give it a shot. I may as well try everything possible since I'm so early in the project.

ch...@clearcrystalmedia.com

unread,
Apr 5, 2009, 5:18:37 PM4/5/09
to ColdFusion on Wheels
I promise that this isn't me telling you to shut up. But my CMS is
going to be one such that admin functions are incorporated into the
public interface. I love the idea in this chapter:
http://gettingreal.37signals.com/ch09_One_Interface.php

So the public-facing part of the site needs to be aware of the same
admin session too. A separate Wheels app wouldn't share the session
unless I authenticated the public-facing part against the admin app.
So many ways to solve the problem.

On Apr 5, 4:19 pm, Chris Peters <ch...@clearcrystalmedia.com> wrote:
> No, that's useful Tony. Let me give it a shot. I may as well try everything
> possible since I'm so early in the project.
>

rip747

unread,
Apr 6, 2009, 1:02:00 AM4/6/09
to ColdFusion on Wheels
you can get separate applications to share sessions and application
variables, it's just a little tricky.

you have to enable j2ee session in cfadministrator and also make sure
that the names of the application are the same. believe it or not, ibm
actually has an article about how to go about doing this:

http://www.ibm.com/developerworks/ibm/library/i-coldstudio/

also, if you want to share cookies amongst the applications, you can
accomplish this by using the domain attribute of the cfcookie tag.

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_c_12.html#3839604

Chris Peters

unread,
Apr 6, 2009, 6:15:40 AM4/6/09
to cfwh...@googlegroups.com
Cool. Will give that a shot then because my other approach isn't quite working as planned. I was trying to use events/onmissingtemplate.cfm and events/onerror.cfm to dispatch the URL to the CMS controller.

Per Djurner

unread,
Apr 14, 2009, 11:34:31 AM4/14/09
to cfwh...@googlegroups.com
You need to give each route a unique name and it should work.

Per Djurner

unread,
Apr 14, 2009, 11:36:59 AM4/14/09
to cfwh...@googlegroups.com
I have removed the code that was causing linkTo to fail with those URLs so give it a try again :)
Also, I think you can remove the action="index" part from "adminSettings" as I think the controller/action should be either in the pattern or specified as an argument, not both.

Chris Peters

unread,
Apr 14, 2009, 9:36:12 PM4/14/09
to cfwh...@googlegroups.com
Nice. Thanks. :)
Reply all
Reply to author
Forward
0 new messages