ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
View.php
Go to the documentation of this file.
1 <?php
46 class Slim_View {
47 
51  protected $data = array();
52 
57 
63  public function __construct() {}
64 
72  public function getData( $key = null ) {
73  if ( !is_null($key) ) {
74  return isset($this->data[$key]) ? $this->data[$key] : null;
75  } else {
76  return $this->data;
77  }
78  }
79 
97  public function setData() {
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  }
107 
113  public function appendData( array $data ) {
114  $this->data = array_merge($this->data, $data);
115  }
116 
121  public function getTemplatesDirectory() {
123  }
124 
131  public function setTemplatesDirectory( $dir ) {
132  $this->templatesDirectory = rtrim($dir, '/');
133  }
134 
143  public function display( $template ) {
144  echo $this->render($template);
145  }
146 
153  public function render( $template ) {
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  }
163 
164 }
Add some data
render( $template)
Render template.
Definition: View.php:153
setData()
Set data.
Definition: View.php:97
Add rich text string
The name of the decorator.
$templatesDirectory
Definition: View.php:56
__construct()
Constructor.
Definition: View.php:63
getData( $key=null)
Get data.
Definition: View.php:72
appendData(array $data)
Append data to existing View data.
Definition: View.php:113
Create styles array
The data for the language used.
getTemplatesDirectory()
Get templates directory.
Definition: View.php:121
display( $template)
Display template.
Definition: View.php:143
setTemplatesDirectory( $dir)
Set templates directory.
Definition: View.php:131