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
add comment

2 Answers

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

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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