-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathView.php
43 lines (37 loc) · 961 Bytes
/
View.php
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
namespace app\core;
class View
{
public $title = ''; //string
public function renderView($view, $params = [])
{
$viewContent = $this->rendeOnlyView($view, $params);
$layoutContent = $this->layoutContent();
return str_replace('{{content}}',$viewContent,$layoutContent);
}
public function renderContent($viewContent)
{
$layoutContent = $this->layoutContent();
return str_replace('{{content}}',$viewContent,$layoutContent);
}
protected function layoutContent()
{
$layout = Application::$app->layout;
if (Application::$app->controller) {
$layout = Application::$app->controller->layout;
}
ob_start();
include_once Application::$ROOT_DIR."/views/layouts/$layout.php";
return ob_get_clean();
}
protected function rendeOnlyView($view, $params)
{
foreach ($params as $key => $value) {
$$key = $value;
}
ob_start();
include_once Application::$ROOT_DIR."/views/$view.php";
return ob_get_clean();
}
}
?>