ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Slim_View Class Reference
+ Collaboration diagram for Slim_View:

Public Member Functions

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

Protected Attributes

 $data = array()
 
 $templatesDirectory
 

Detailed Description

Definition at line 46 of file View.php.

Constructor & Destructor Documentation

◆ __construct()

Slim_View::__construct ( )

Constructor.

This is empty but may be overridden in a subclass

Definition at line 63 of file View.php.

63 {}

Member Function Documentation

◆ appendData()

Slim_View::appendData ( array  $data)

Append data to existing View data.

Parameters
array$data
Returns
void

Definition at line 113 of file View.php.

References data.

113  {
114  $this->data = array_merge($this->data, $data);
115  }
Add some data

◆ display()

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().

143  {
144  echo $this->render($template);
145  }
render( $template)
Render template.
Definition: View.php:153
+ Here is the call graph for this function:

◆ getData()

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, and data.

72  {
73  if ( !is_null($key) ) {
74  return isset($this->data[$key]) ? $this->data[$key] : null;
75  } else {
76  return $this->data;
77  }
78  }
Add some data

◆ getTemplatesDirectory()

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().

121  {
123  }
$templatesDirectory
Definition: View.php:56
+ Here is the caller graph for this function:

◆ render()

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 data, and getTemplatesDirectory().

Referenced by display().

153  {
154  extract($this->data);
155  $templatePath = $this->getTemplatesDirectory() . '/' . ltrim($template, '/');
156  if ( !file_exists($templatePath) ) {
157  throw new RuntimeException('View cannot render template `' . $templatePath . '`. Template does not exist.');
158  }
159  ob_start();
160  require $templatePath;
161  return ob_get_clean();
162  }
Add some data
getTemplatesDirectory()
Get templates directory.
Definition: View.php:121
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setData()

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.

References data, and string.

97  {
98  $args = func_get_args();
99  if ( count($args) === 1 && is_array($args[0]) ) {
100  $this->data = $args[0];
101  } else if ( count($args) === 2 ) {
102  $this->data[(string)$args[0]] = $args[1];
103  } else {
104  throw new InvalidArgumentException('Cannot set View data with provided arguments. Usage: `View::setData( $key, $value );` or `View::setData([ key => value, ... ]);`');
105  }
106  }
Add some data
Add rich text string
The name of the decorator.

◆ setTemplatesDirectory()

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.

131  {
132  $this->templatesDirectory = rtrim($dir, '/');
133  }

Field Documentation

◆ $data

Slim_View::$data = array()
protected

Definition at line 51 of file View.php.

Referenced by getData().

◆ $templatesDirectory

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: