Path

ez components / documentation / api reference / latest / url


eZ Components latest

Url: ezcUrlCreator

[ Tutorial ] [ Class tree ] [ Element index ] [ ChangeLog ] [ Credits ]

Class: ezcUrlCreator

ezcUrlCreator makes it easy to create urls from scratch. [source]
Holds a list of urls mapped to aliases. The aliases are used to refer to the urls stored, so the urls will not be hardcoded all over the application code.
Example of use:
 1.  // register an URL under the alias 'map'
 2.   ezcUrlCreator::registerUrl'map''/images/geo/%s?xsize=%d&ysize=%d&zoom=%d' );
 3.  
 4.  // retrieve the stored URL under the alias 'map' formatted with parameters
 5.   $url ezcUrlCreator::getUrl'map''map_norway.gif'450450);
 6.       // will be: "/images/geo/map_norway.gif?xsize=450&ysize=450&zoom=4"
 7.  
 8.  // retrieve the stored URL under the alias 'map' formatted with other parameters
 9.   $url ezcUrlCreator::getUrl'map''map_sweden.gif'450450);
 9.       // will be: "/images/geo/map_sweden.gif?xsize=450&ysize=450&zoom=4"

Method Summary

public static string getUrl( $name, $args,... )
Returns the URL registered as $name.
public static string prependUrl( $name, $suffix )
Returns the URL registerd as $name prepended to $suffix.
public static void registerUrl( $name, $url )
Registers $url as $name in the URLs list.

Methods

getUrl

string getUrl( string $name, mixed $args,... )
Returns the URL registered as $name.
This function accepts a variable number of arguments like the sprintf() function. If you specify more than 1 arguments when calling this function, the registered URL will be formatted using those arguments similar with the sprintf() function. Example:
1.  ezcUrlCreator::registerUrl'map''/images/geo/%s?xsize=%d&ysize=%d&zoom=%d' );
2.  echo ezcUrlCreator::getUrl'map''map_sweden.gif'450450);
will output: /images/geo/map_sweden.gif?xsize=450&ysize=450&zoom=4

Parameters

Name Type Description
$name string The name associated with the URL
$args,... mixed Optional values which will be vsprintf-ed in the URL

Throws

ClassDescription
ezcUrlNotRegisteredException if $name is not registered

prependUrl

string prependUrl( string $name, string $suffix )
Returns the URL registerd as $name prepended to $suffix.
Example:
1.  ezcUrlCreator::registerUrl'map''/images/geo?xsize=450&ysize=450&zoom=4' );
2.  echo ezcUrlCreator::prependUrl'map''map_sweden.gif' );
will output: /images/geo/map_sweden.gif?xsize=450&ysize=450&zoom=4

Parameters

Name Type Description
$name string The name associated with the URL that will be appended with $suffix
$suffix string The string which will be appended to the URL

Throws

ClassDescription
ezcUrlNotRegisteredException if $name is not registered

registerUrl

void registerUrl( string $name, string $url )
Registers $url as $name in the URLs list.
If $name is already registered, it will be overwritten.

Parameters

Name Type Description
$name string The name associated with the URL
$url string The URL to register

Last updated: Mon, 10 Nov 2008