Added ability to dynamically create links to named routes using the HTML class.

This commit is contained in:
Taylor Otwell 2011-06-30 07:31:57 -07:00
parent b90c6ddcc5
commit 6af79d8bdb
1 changed files with 52 additions and 0 deletions

View File

@ -76,6 +76,34 @@ public static function link_to_asset($url, $title, $attributes = array())
return static::link($url, $title, $attributes, false, true);
}
/**
* Generate an HTML link to a route.
*
* @param string $name
* @param string $title
* @param array $parameters
* @param array $attributes
* @return string
*/
public static function link_to_route($name, $title, $parameters = array(), $attributes = array(), $https = false)
{
return static::link(URL::to_route($name, $parameters, $https), $title, $attributes);
}
/**
* Generate an HTTPS HTML link to a route.
*
* @param string $name
* @param string $title
* @param array $parameters
* @param array $attributes
* @return string
*/
public static function link_to_secure_route($name, $title, $parameters = array(), $attributes = array())
{
return static::link_to_route($name, $title, $parameters, $attributes, true);
}
/**
* Generate an HTML mailto link.
*
@ -250,4 +278,28 @@ public static function obfuscate($value)
return $safe;
}
/**
* Magic Method for handling dynamic static methods.
*/
public static function __callStatic($method, $parameters)
{
// -------------------------------------------------------
// Handle the dynamic creation of links to secure routes.
// -------------------------------------------------------
if (strpos($method, 'link_to_secure_') === 0)
{
array_unshift($parameters, substr($method, 15));
return forward_static_call_array('HTML::link_to_secure_route', $parameters);
}
// -------------------------------------------------------
// Handle the dynamic creation of links to routes.
// -------------------------------------------------------
if (strpos($method, 'link_to_') === 0)
{
array_unshift($parameters, substr($method, 8));
return forward_static_call_array('HTML::link_to_route', $parameters);
}
}
}