Features

Net_URL_Mapper can handle different types of mapping:

In the following examples we assume that URLs are mapped to a desginated controller and an action. But the controller and action keys provided could be called anything and are not mandatory.

Static path parts

The following code snippet maps the URL /home:

<?php
require_once 'Net/URL/Mapper.php';

$m Net_URL_Mapper::getInstance();
$m->connect('home', array('controller' => 'index''action' => 'index'));
var_dump($m->match($_SERVER['REQUEST_URI']));
?>

Dynamic path parts

The following code snippet maps a URL such as /news/1, /news/2 to a designated controller and action.

<?php
require_once 'Net/URL/Mapper.php';

$m Net_URL_Mapper::getInstance();
$m->connect('news/:id', array('controller' => 'news''action' => 'read'));
var_dump($m->match($_SERVER['REQUEST_URI']));
?>

Wildcard path parts

The following code snippet maps all URLs with /content to a controller called content and an action called display. Optionally, we'll determine the section on the page using a wildcard. The default for section is #toc (Table Of Contents).

<?php
require_once 'Net/URL/Mapper.php';

$m Net_URL_Mapper::getInstance();

$path     'content/*(section)';
$defaults = array(
    
'controller' => 'content',
    
'action'     => 'display',
    
'section'    => '#toc',
);

$m->connect($path$defaults);
var_dump($m->match($_SERVER['REQUEST_URI']));
?>
Introduction (Previous) Examples (Next)
Last updated: Thu, 21 Aug 2014 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

There are no user contributed notes for this page.