$mapper
$mapper : \Horde_Routes_Mapper
Utility functions for use in templates and controllers
$mapper : \Horde_Routes_Mapper
__construct(\Horde_Routes_Mapper $mapper, callback $redirect = null)
Constructor
\Horde_Routes_Mapper | $mapper | Mapper for these utilities |
callback | $redirect | Redirect callback for redirectTo() |
urlFor( $first = array(), $second = array())
Generates a URL.
All keys given to urlFor are sent to the Routes Mapper instance for generation except for::
anchor specified the anchor name to be appened to the path
host overrides the default (current) host if provided
protocol overrides the default (current) protocol if provided
qualified creates the URL with the host/port information as
needed
The URL is generated based on the rest of the keys. When generating a new URL, values will be used from the current request's parameters (if present). The following rules are used to determine when and how to keep the current requests parameters:
For example, if the current request yielded a dict (associative array) of array('controller'=>'blog', 'action'=>'view', 'id'=>2), with the standard ':controller/:action/:id' route, you'd get the following results::
urlFor(array('id'=>4)) => '/blog/view/4',
urlFor(array('controller'=>'/admin')) => '/admin',
urlFor(array('controller'=>'admin')) => '/admin/view/2'
urlFor(array('action'=>'edit')) => '/blog/edit/2',
urlFor(array('action'=>'list', id=NULL)) => '/blog/list'
Static and Named Routes
If there is a string present as the first argument, a lookup is done against the named routes table to see if there's any matching routes. The keyword defaults used with static routes will be sent in as GET query arg's if a route matches.
If no route by that name is found, the string is assumed to be a raw URL.
Should the raw URL begin with /
then appropriate SCRIPT_NAME data will
be added if present, otherwise the string will be used as the url with
keyword args becoming GET query args.
$first | ||
$second |
redirectTo(mixed $first = array(), mixed $second = array()) : mixed
Issues a redirect based on the arguments.
Redirects should occur as a "302 Moved" header, however the web framework may utilize a different method.
All arguments are passed to urlFor() to retrieve the appropriate URL, then the resulting URL it sent to the redirect function as the URL.
mixed | $first | First argument in varargs, same as urlFor() |
mixed | $second | Second argument in varargs |
Result of redirect callback
controllerScan(string $dirname = null, string $prefix = '') : array
Scan a directory for PHP files and use them as controllers. Used as the default scanner callback for Horde_Routes_Mapper. See the constructor of that class for more information.
Given a directory with: foo.php, bar.php, baz.php Returns an array: foo, bar, baz
string | $dirname | Directory to scan for controller files |
string | $prefix | Prefix controller names (optional) |
Array of controller names