ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
Slim_View Class Reference
+ Collaboration diagram for Slim_View:

Public Member Functions

 __construct ()
 Constructor.
 getData ($key=null)
 Get data.
 setData ()
 Set data.
 appendData (array $data)
 Append data to existing View data.
 getTemplatesDirectory ()
 Get templates directory.
 setTemplatesDirectory ($dir)
 Set templates directory.
 display ($template)
 Display template.
 render ($template)
 Render template.

Protected Attributes

 $data = array()
 $templatesDirectory

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
array$data
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$templatePath to template file relative to templates directoy
Returns
void

Definition at line 143 of file View.php.

References render().

{
echo $this->render($template);
}

+ Here is the call graph for this function:

Slim_View::getData (   $key = null)

Get data.

Parameters
string$key
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 {
return $this->data;
}
}
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().

+ Here is the caller graph for this function:

Slim_View::render (   $template)

Render template.

Parameters
string$templatePath to template file relative to templates directory
Returns
string Rendered template
Exceptions
RuntimeExceptionIf template does not exist

Definition at line 153 of file View.php.

References getTemplatesDirectory().

Referenced by display().

{
extract($this->data);
$templatePath = $this->getTemplatesDirectory() . '/' . ltrim($template, '/');
if ( !file_exists($templatePath) ) {
throw new RuntimeException('View cannot render template `' . $templatePath . '`. Template does not exist.');
}
ob_start();
require $templatePath;
return ob_get_clean();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Slim_View::setData ( )

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
mixedOptional. Only use if first argument is a string.
Returns
void
Exceptions
InvalidArgumentExceptionIf 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
string$dir
Returns
void
Exceptions
RuntimeExceptionIf 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

Definition at line 51 of file View.php.

Referenced by getData().

Slim_View::$templatesDirectory
protected

Definition at line 56 of file View.php.

Referenced by getTemplatesDirectory().


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