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 Page History

« Previous Version 9 Next »

CONTENIDO offers a package of helper classes to work with URIs.

cUri

The cUri class allows to create and parse frontend URIs i.e. URIs to CONTENIDO articles and categories. By default 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.

Building an URI

The easiest way to build an URI to an arbitray article is as follows:

$param['idart'] = $idart;
$param['lang'] = $lang;
$url = cUri::getInstance()->build($param);

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. If another builder than cUriBuilderFrontcontent is used (see below) further keys may be required.

You can give the data as a default URI too. In this case the given URI is parsed (see below) before building it anew.

$url = "front_content.php?idart=$idart&lang=$lang";
$url = cUri::getInstance()->build($url);

URI to current article

If you like to create a link to the current article you can use this snippet instead which gets the values for the current language and article from the registry:

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

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);

Instead of using this second argument you can use a wrapper method called buildRedirect() which does the same.

The name of the method buildRedirect() is a bit misleading though!

Using different 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.

Building an URI by components

TODO

Parse an URI

The cUri class also offers a parse() method which allows for splitting an URI into its components (thats what the PHP function parse_url does) which is extended by the key 'params' that contains name, value pairs for each parameter of the given URI.

$components = cUri::getInstance()->parse($url);

 

cUriBuilderFactory & cUriBuilder

cUriBuilderCustom

cUriBuilderCustomPath

cUriBuilderFrontcontent

cUriBuilderMR

cUriBuilderConfig

  • No labels