Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Version History

« Previous Version 3 Next »

The URI helper 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:

$param = 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:

$url = cUri::getInstance()->build(array(
    'lang' => cRegistry::getLanguageId(),
    'idart' => cRegistry::getArticleId()
));

The called build()-method expects an associative array wich has to have at least a value for the key lang 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:

$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:

$config = array();
$url = cUri::getInstance()->build($param, $absolute, $config);

Which options this configuration array may contain will be explained later.

  • No labels