Pretty urls

Create issue
Issue #37 new
Jelmer van der Linde created an issue

Use mod_rewrite to make many urls prettier and less meaningless than show.php?id=24.

Proposal

Introduce a router.php file that catches all urls that are not directly linked to a file. This file would then use some regular expressions and maybe look through some of the models to find the appropriate resource and then start the corresponding controller.

Requirements

The old links should still function and preferably permanently redirect to the new urls.

Required changes

The above would require at least the following changes:

  1. Links should be generated. Many of the controllers and views extending ControllerCRUD already use $controller->link_to_read($iter) etc, but this should be more abstract to allow for inter-controller links. E.g. get_url('topic.read', $iter). The router should then create a pretty link, such as /forum/general/quotes/4 (page 4 of the quotes topic in the general category)

  2. Controller files should be loadable without them running. Currently, many controllers run as soon as you load their class definition. That is not what we would like.

  3. The router should give us some way to call methods directly, but with the complete layout pre- and post-request operations. Currently this is handled by Controller::run(). Maybe an argument on which controller to call would help but then the functionality of `Controller::run_impl()`` would have to be reproduced or moved to individual controller methods. This would also break backward compatibility with the current urls.

  4. An alternative to 3. would be to populate $_GET from the router and run the controller as they do now.

Comments (1)

  1. Log in to comment