73 if ( !is_null($key) ) {
74 return isset($this->data[$key]) ? $this->data[$key] : null;
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];
104 throw new InvalidArgumentException(
'Cannot set View data with provided arguments. Usage: `View::setData( $key, $value );` or `View::setData([ key => value, ... ]);`');
114 $this->data = array_merge($this->data, $data);
132 $this->templatesDirectory = rtrim($dir,
'/');
144 echo $this->
render($template);
154 extract($this->data);
156 if ( !file_exists($templatePath) ) {
157 throw new RuntimeException(
'View cannot render template `' . $templatePath .
'`. Template does not exist.');
160 require $templatePath;
161 return ob_get_clean();