.

ActionMapper Class Reference
[Controller]

Maps actions to URLs. More...

List of all members.

Static Public Member Functions

static  equals_current ($action, $params=null)
  Returns true, if the given action route equals current URL.
static  force_path ($action, $params=null)
  Returns path for given action.
static  get_path ($action, $params=null)
  Returns path for given action.
static  get_url ($action, $params=null)
  Returns url for given action.
static  register_url ($action, $urlbuilder)
  Registers URL builder for action.
static  validate_against_current ($action, $params=null)
  Checks if given action route matches current URL, if not redirects.

Detailed Description

Maps actions to URLs.

The ActionMapper allows to retrieve the URL for a given action, including possible parameters.

Given a model "blog" and an action blog_view on Controler BlogControler to show a blog entry defined as a ParameterizedRoute of 'blog/{id:ui>}'. The url of a given blog entry can now be retrieved like this:

 $blog = Blog::get($id); // Get blog entry with given id
 $s_url = ActionMapper::get_url('view', $blog); // Retrieve url to view entry
Author:
Gerd Riesselmann

Definition at line 20 of file actionmapper.cls.php.


Member Function Documentation

static ActionMapper::equals_current ( action,
params = null  
) [static]

Returns true, if the given action route equals current URL.

Parameters:
string  $action Action name
mixed  $params Parameters, depend on action
Returns:
bool

Definition at line 94 of file actionmapper.cls.php.

00094                                                                        {
00095                 return Url::current()->equals(self::get_url($action, $params), Url::EQUALS_IGNORE_QUERY);
00096         }
static ActionMapper::force_path ( action,
params = null  
) [static]

Returns path for given action.

Path is relative to web root. Even if protocol or host do not match, only the path will be returned. Use this for images, e.g.

Parameters:
string  $action Action name
mixed  $params Parameters, depend on action
Returns:
string

Definition at line 57 of file actionmapper.cls.php.

00057                                                                    {
00058                 $url = self::build_url($action, $params, IUrlBuilder::ABSOLUTE);
00059                 return '/' . Url::create($url)->get_path();
00060         }
static ActionMapper::get_path ( action,
params = null  
) [static]

Returns path for given action.

Path is relative to web root, although an url builder may decide to return an absolute url (including "http://"!) nonetheless (e.g. if https is required for action url)

Parameters:
string  $action Action name
mixed  $params Parameters, depend on action
Returns:
string

Definition at line 45 of file actionmapper.cls.php.

00045                                                                  {
00046                 return self::build_url($action, $params, IUrlBuilder::RELATIVE);
00047         }
static ActionMapper::get_url ( action,
params = null  
) [static]

Returns url for given action.

Path is absolute

Parameters:
string  $action Action name
mixed  $params Parameters, depend on action
Returns:
string

Definition at line 70 of file actionmapper.cls.php.

00070                                                                 {
00071                 return self::build_url($action, $params, IUrlBuilder::ABSOLUTE);
00072         }
static ActionMapper::register_url ( action,
urlbuilder  
) [static]

Registers URL builder for action.

Parameters:
string  $action Action name
IUrlBuilder  $urlbuilder The builder for given action

Definition at line 33 of file actionmapper.cls.php.

00033                                                                   {
00034                 self::$actions[$action] = $urlbuilder;
00035         }
static ActionMapper::validate_against_current ( action,
params = null  
) [static]

Checks if given action route matches current URL, if not redirects.

Parameters:
string  $action Action name
mixed  $params Parameters, depend on action

Definition at line 80 of file actionmapper.cls.php.

00080                                                                                  {
00081                 $url = Url::create(self::get_url($action, $params));
00082                 if (!Url::current()->equals($url, Url::EQUALS_IGNORE_QUERY)) {
00083                         $url->redirect(Url::PERMANENT);
00084                 }
00085         }

The documentation for this class was generated from the following file: