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.

Do they mean the same thing (attaching URLs to actions, or actions to URLs) or is there any difference I'm missing?

Example: http://github.com/dannyvankooten/PHP-Router vs. http://konstrukt.dk

share|improve this question
    
that router sounds more like a glorified proxy to me –  ratchet freak Feb 17 '12 at 2:21

4 Answers 4

Router:

Routing is the process of taking a URI endpoint (that part of the URI which comes after the base URL) and decomposing it into parameters to determine which module, controller, and action of that controller should receive the request.

Controller:

Controller implements a »Controller pattern, in which all requests are intercepted by controller and dispatched to individual Action Controllers based on the URL requested(that is routing request from Router).

share|improve this answer

The route maps a URL to a controller, which is the action. Sometimes the roles are not really separated very well depending on the framework.

share|improve this answer

Quite simply a router works out a journey through the application, usually based upon external input such as GET or POST variables.

A Router is not however any part of an MVC, several MVC and HMVC frameworks use routers, but this does not bind them to the pattern of MVC.

Additionally several early implementations of MVC I have seen actually relied on file-based separation of actions with one file per controller for accessing separate controllers. This serves the application much better, because by having skinny controllers, with more robust models, you never have to scroll to a particular method in the controller, and you can therefore access the logic in one place (the model), allowing you to composite behaviours.

share|improve this answer

A Frontend-Controller should collaborate with a Router and a Dispatcher to decide based on the (HTTP) request against the application which concrete Action has to be executed and then dispatches it.

Depending on how detailed a design is, some Controllers work without Routers and they do the routing their own or the routing is implicit in the design how the request is processed.

Some Dispatchers also pass a Request object to the dispatched action methods. Action-Methods then decompose themselves the Request in part so that even Controller actions still can do some routing based on the request. A typical example for this is the case when a framework offers to do a redirect as the response. This also shows how related or near Router and Controller are.

The difference that is normally drawn here is that the routing takes care of or helps with identifying which action method to execute and the controller then is responsible to provide this action but both handle the request.

As you can see, the differences between Router and Controller can vary greatly between implementations and frameworks. In the end, the concrete application has it's needs whether or not a certain level of abstraction is useful or stands in the way.

However from the terms I'd say that Controller is in a higher role in the overall application. This is where the action goes so to say.

share|improve this answer

Your Answer

 
discard

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.