-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathView.class.php
More file actions
43 lines (36 loc) · 1.59 KB
/
View.class.php
File metadata and controls
43 lines (36 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
// The View class is responsible for all interaction with the users. Our View class builds
// upon the Smarty template system to combine data and HTML in a clean way.
// The View is loaded by creating a new View instance for every View. The responsibility for
// loading a View and sending it to the user lies with the Controller.
// All data loading should thus, in general, happen in the Controller. There are exceptions
// with special cases.
class View {
private $smarty;
// Create a new View and run the Smarty display of the given template
public function __construct($template, $variables = array()) {
if(is_array($template)) throw new Exception("The template name have to be a string.");
// Get Smarty
$this->smarty = new Smarty; // Prepare template rendering
$this->smarty->plugins_dir[] = 'libs/rasplugins'; // Load RAS Smarty plugins
$this->smarty->assign('root', Tools::rootURL()); // We want absolute URLs
$this->smarty->assign('apache', Tools::canRewrite()); // Pretty URLs or not?
// Set Smarty dynamic Smarty variables
foreach($variables as $name=>$value) {
$this->smarty->assign($name, $value);
}
// Archive submenu (special case)
$this->smarty->assign('years', Post::getYears());
// Render the Smarty template
try {
$this->smarty->display($template);
} catch (SmartyException $e) {
echo $e->getMessage()."<br/>";
}
}
// Can we send mail?
public function mailSupport() {
return Tools::toBeOrNotToBe();
}
}
?>