Added View::of method and $view->partial() method.

This commit is contained in:
Taylor Otwell 2011-07-26 14:35:44 -05:00
parent 989ba6743b
commit f4f82d1761
1 changed files with 33 additions and 8 deletions

View File

@ -49,6 +49,25 @@ public static function make($view, $data = array())
return new static($view, $data);
}
/**
* Create a new named view instance.
*
* @param string $view
* @param array $data
* @return View
*/
public static function of($view, $data = array())
{
$views = Config::get('view.names');
if ( ! array_key_exists($view, $views))
{
throw new \Exception("Named view [$view] is not defined.");
}
return static::make($views[$view], $data);
}
/**
* Get the parsed content of the view.
*
@ -98,6 +117,19 @@ protected function find()
}
}
/**
* Add a view instance to the view data.
*
* @param string $key
* @param string $view
* @param array $data
* @return View
*/
public function partial($key, $view, $data = array())
{
return $this->bind($key, View::make($view, $data));
}
/**
* Add a key / value pair to the view data.
*
@ -118,14 +150,7 @@ public static function __callStatic($method, $parameters)
{
if (strpos($method, 'of_') === 0)
{
$views = Config::get('view.names');
if ( ! array_key_exists($view = substr($method, 3), $views))
{
throw new \Exception("Named view [$view] is not defined.");
}
return static::make($views[$view], (isset($parameters[0]) and is_array($parameters[0])) ? $parameters[0] : array());
return static::of(substr($method, 3), Arr::get($parameters, 0, array()));
}
}