Detailed Description
Definition at line 46 of file View.php.
Constructor & Destructor Documentation
Slim_View::__construct |
( |
| ) |
|
Constructor.
This is empty but may be overridden in a subclass
Definition at line 63 of file View.php.
Member Function Documentation
Slim_View::appendData |
( |
array |
$data | ) |
|
Append data to existing View data.
- Parameters
-
- Returns
- void
Definition at line 113 of file View.php.
{
$this->data = array_merge($this->data,
$data);
}
Slim_View::display |
( |
|
$template | ) |
|
Display template.
This method echoes the rendered template to the current output buffer
- Parameters
-
string | $template | Path to template file relative to templates directoy |
- Returns
- void
Definition at line 143 of file View.php.
References render().
{
echo $this->
render($template);
}
Slim_View::getData |
( |
|
$key = null | ) |
|
Get data.
- Parameters
-
- Returns
- array|mixed|null All View data if no $key, value of datum if $key, or NULL if $key but datum does not exist.
Definition at line 72 of file View.php.
References $data.
{
if ( !is_null($key) ) {
return isset($this->data[$key]) ? $this->data[$key] : null;
} else {
}
}
Slim_View::getTemplatesDirectory |
( |
| ) |
|
Get templates directory.
- Returns
- string|null Path to templates directory without trailing slash
Definition at line 121 of file View.php.
References $templatesDirectory.
Referenced by render().
Slim_View::render |
( |
|
$template | ) |
|
Render template.
- Parameters
-
string | $template | Path to template file relative to templates directory |
- Returns
- string Rendered template
- Exceptions
-
RuntimeException | If template does not exist |
Definition at line 153 of file View.php.
References getTemplatesDirectory().
Referenced by display().
{
extract($this->data);
if ( !file_exists($templatePath) ) {
throw new RuntimeException('View cannot render template `' . $templatePath . '`. Template does not exist.');
}
ob_start();
require $templatePath;
return ob_get_clean();
}
Set data.
This method is overloaded to accept two different method signatures. You may use this to set a specific key with a specfic value, or you may use this to set all data to a specific array.
USAGE:
View::setData('color', 'red'); View::setData(array('color' => 'red', 'number' => 1));
- Parameters
-
string|array | |
mixed | Optional. Only use if first argument is a string. |
- Returns
- void
- Exceptions
-
InvalidArgumentException | If incorrect method signature |
Definition at line 97 of file View.php.
{
$args = func_get_args();
if ( count($args) === 1 && is_array($args[0]) ) {
$this->data = $args[0];
} else if ( count($args) === 2 ) {
$this->data[(string)$args[0]] = $args[1];
} else {
throw new InvalidArgumentException('Cannot set View data with provided arguments. Usage: `View::setData( $key, $value );` or `View::setData([ key => value, ... ]);`');
}
}
Slim_View::setTemplatesDirectory |
( |
|
$dir | ) |
|
Set templates directory.
- Parameters
-
- Returns
- void
- Exceptions
-
RuntimeException | If directory is not a directory or does not exist |
Definition at line 131 of file View.php.
{
$this->templatesDirectory = rtrim($dir, '/');
}
Field Documentation
Slim_View::$data = array() |
|
protected |
Slim_View::$templatesDirectory |
|
protected |
The documentation for this class was generated from the following file:
- Services/WebServices/Rest/lib/Slim/View.php