Explain the different ways skeleton can handle URL's (both parameter based and clean)
This class adds/modifies the values in the Request object, so the code can be used with mod_rewrite and the Mapper, or without. The default parameters are controller and action, but these two parameter names can be changed by passing a different map to the constructor.
To use without mod_rewrite and only a Request class, URLs would look like:
www.mydomain.com?controller=people&action=list&sort=name
With mod_rewrite and this class, URLs look like:
www.mydomain.com/people/list/sort/name/
Either way the same values in the Request object would be set: 'controller', 'action' and 'sort'
A basic .htaccess file for use with mod_rewrite is:
RewriteEngine on
RewriteRule !\.[a-zA-Z0-9]{2,4}$ index.php
This is the format for mapping PATH_INFO values onto request vars:
$map = array(
'' => array( // '' is the route array used when no match is found
'controller', // position in PATH_INFO and requestprotected to map onto
'action',
'id',
),
'date' => array( // if 'date' is found in the first element of PATH_INFO use the map below
'' => array(
'controller',
'year',
'month',
'day',
),
),
);
The mapper starts at the root level of the array and searches keys for a match on the first element in the PATH_INFO. If a key match is found it then uses the array under that key to search the next element in PATH_INFO. If no match is found then the [''] index in the array is used. Every array should have a [''] key containing the route array to use to map PATH_INFO to Request vars.
In the example above, the PATH_INFO of "/view/person/Bob/" will map to the Request as "?controller=view&action=person&id=Bob" because 'view' does not match a key in the root array of the map, in this map that is '' and 'date'. The [''] array at the level where no match was found is used for the mapping. The PATH_INFO of "/date/2006/January/1st/" will map to the Request as "?controller=date&year=2006&month=January&day=1st" because 'date' matches a key in the map.
Additional parameters in the PATH_INFO past those defined in the map with be combined in pairs to request vars. For example, /view/person/Bob/age/42/height/84/ will map the the Reqest as "?controller=view&action=person&id=Bob&age=42&height=84". This can be turned off with the $map_extra_param_pairs parameter.
The position where mapping stopped is saves so additional maps can be applied to PATH_INFO. For example, the Front Http might map the first two values in PATH_INFO to the default /controller/action/ parameters. Different dispatched controllers may then set their own maps to map the parameters in PATH_INFO starting at the third parameter.
Here is an example use in the bootstrap:
<?php
// ...
$Request = new A_Http_Request();
$map = array(
'' => array( // '' is the route array used when no match is found
'controller', // position in PATH_INFO and requestprotected to map onto
'action',
'id',
),
'date' => array( // if 'date' is found in the first element of PATH_INFO use the map below
'' => array(
'controller',
'year',
'month',
'day',
),
),
);
$Pathinfo = new A_Http_Pathinfo($map);
// process Request according to map
$Pathinfo->run($Request);
// ...