Creating Custom URLs in Your Wheels App with Routes


Today, I released a chapter in the Documentation called Using Routes.

Routes are a pretty cool feature of Wheels because they let you step outside of the URL convention that can sometimes feel like shackles.

As I outline in the new chapter, you can create a URL like this:

http://www.domain.com /user/johndoe

With this line of code in your config/routes.cfm file:

<cfset addRoute(name=”userProfile”, pattern=”user/[username]”, controller=”user”, action=”profile”)>

Read on to find out how it all works.

Comments

  1. Raul Riera says:

    Keep up the good work man hehe, if u need anything let us know. Btw is this blog running on wheels?

  2. Raul Riera says:

    Shouldn’t this be

    http://www.domain.com/news/1/story/5

    instead of

    http://www.domain.com/news/story/5

    I think there should be an ID for the news right?

  3. Chris Peters says:

    @Raul:

    No, the format I have is correct.

    Match this…
    http://www.domain.com/news/story/5

    To this…
    http://www.domain.com/controller/action/id

    And you get this…
    controller = news
    action = story
    id = 5

    That is the default route for Wheels.

  4. Chris Peters says:

    Also, this blog is running on Ray Camden’s BlogCFC. There was no need to re-invent the wheel on blogging platforms. We’ll see if one gets implemented in Wheels in the future… 🙂

  5. Raul Riera says:

    Oh I see, I though it was a News tha hasMany Stories. I thought they were 2 models.