Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm looking for new ways of dealing with the problem of finding the correct controller to deal with the resource the user is requesting.

Most frameworks simply parse the URI out into segments, check for any rewrite rules, and then finally load a controller with the same name.

example.com/user/update/4 -> Controller_User.update($id = 4);

What other ways are there to handle this resource-to-action problem? Are their any unique methods systems out there use?

share|improve this question

put on hold as too broad by gnat, Bart van Ingen Schenau, MichaelT, Ampt, Dan Pichelman Jul 7 at 14:01

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

add comment

2 Answers

You might be interested in traversal. This page details the Pyramid (formerly repoze.bfg) implementation of the traversal idea.

share|improve this answer
add comment

In Django, you define a list of pairs, where each pair contains: a) a regular expression, and b) a controller that takes at most as many parameters as there are capturing groups in the expression. Each incoming URL is tested against each regular expression, in order. If the expression matches, then the controller is called and its parameters are filled by the capturing groups in the regex.

It's very powerful and very simple. On my homepage I have a Javascript implementation that takes around half a page of code.

share|improve this answer
+1 For creating a list of mapps using regexps between URL and handler. Have a look at this to wet your appetite. –  Martin Wickman May 2 '11 at 10:05
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.