The cUri URI helper class classes allows to create and parse frontend URIs i.e. URIs to CONTENIDO articles. Usually these URIs look like front_content.php?lang=<lang>&idart=<idart>
. The cUri allows for totally different URIs e.g. SEO-URIs that contain names of categories and articles instead of the strange looking URI mentioned above. In order to create these URIs independant of the chosen strategy for URI creation it is a good idea to use the cUri class whose functionality will be explained in this article.
Create an URI
The easiest way to create a link to an arbitray article is as follows:
Code Block | ||||
---|---|---|---|---|
| ||||
$url$param = cUri::getInstance()->build(array( 'lang' => $lang, 'idart' => $idart ); $url = cUri::getInstance()->build($param); |
URI to current article
If you like to create a link to the current article you can use this snippet instead:
...
The called build()-method expects an associative array wich has to have at least values a value for the keys key lang & idart but any parameter can be appended.
Relative vs. absolute URIs
By default a relative URI is created but creation of an absolute URI can be forced with a second argument set to true:
Code Block | ||||
---|---|---|---|---|
| ||||
$absolute = true;
$url = cUri::getInstance()->build($param, $absolute);
|
Configuration
How the URI will be created can be configured in detail. If you want to overwrite this configuration for the creation of a single URI you can pass a third argument:
Code Block | ||||
---|---|---|---|---|
| ||||
$config = array();
$url = cUri::getInstance()->build($param, $absolute, $config);
|
Which options this configuration array may contain will be explained later.