Url handling

behringer24 edited this page Jun 5, 2011 · 4 revisions

To simplify routing and URL rewriting activeCube offers the acUrlHelper static class. URLs are configured as routes in the routing.ini configuration file.

pattern = "/news/{id}/{title}.htm"
mod = news

pattern = "/contact"
mod = contact

Each section configures one route. The pattern defines the fixed and variable parts of the URL. The variables are defined by their names in brackets and will be set as request parameters. The lines below can set additional request parameters. Most important: mod is allways the parameter for the module to load.

URL generation

Routes are named, this makes referencing them easy. In your template you can write

<a href='<?php echo acUrlHelper::getUrl('Routename', array(
	'id' => 1234,
	'title' => 'url-seo-title-optimization'	
)); ?>'>Url seo title optimization</a>

This will output

<a href='/news/1234/url-seo-title-optimization.htm'>Url seo title optimization</a>

So if you want to change the links to your news section you just change the route pattern.

Request URL pattern matching

In the other direction if a user requests your server first of all the .htaccess redirects all requests that do not point to an existing file in your docroot of the server to the index.php (called your frontcontroller).

First activeCube tries to match all configured routes to the request url. If a matching route pattern is found it is used - this implicates that any later match is not even checked so the order of routes is important.

Handling the default case

If no pattern can be found activeCube splits the URL up like this

/mod/varname1/value1/varname2/value2/varname3/value3/ ...