Misago\ActionController\Routing

Classes:

Functions:

url_for($options)

Resolves an URL (reverse routing).

Options:

  • anchor - adds an anchor to the URL.
  • path_only - false to return an absolute URI, true to return the path only (defaults to true).
  • protocol - overwrites the current protocol.
  • host - overwrites the current host.
  • port - overwrites the current port.
  • user - username for HTTP login.
  • password - password for HTTP login.

Example:

url_for(array(':controller' => 'products', ':action' => 'show', ':id' => '67'))
# => http://www.domain.com/products/show/67 

Any unknown option that isn't a symbol is added to the query string:

url_for(array(':controller' => 'products', 'order' => 'asc'))
# => http://www.domain.com/products?order=asc

url_for(array(':controller' => 'products', ':action' => 'show', ':id' => 13, 'comments' => 'show'))
# => http://www.domain.com/products/show/13?comments=show 

You may also add an anchor:

url_for(array(':controller' => 'about', 'anchor' => 'me'))
# => http://www.domain.com/about#me 

Using REST resources, you may pass an \Misago\ActiveRecord directly. For instance:

$product = new Product(43);
$url = url_for(product);    # => http://www.domain.com/products/3 

IMPROVE: url_for: handle specified options (host, protocol, etc.) IMPROVE: url_for: permit for simplified calls, like url_for(array(':action' => 'index')), which shall use the current controller.