-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathView.php
More file actions
30 lines (26 loc) · 864 Bytes
/
View.php
File metadata and controls
30 lines (26 loc) · 864 Bytes
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
<?php namespace binotby\phpcorefaster;
class View
{
public string $title = '';
public function renderView($view, array $params)
{
$layoutName = Application::$app->layout;
if (Application::$app->controller) {
$layoutName = Application::$app->controller->layout;
}
$viewContent = $this->renderViewOnly($view, $params);
ob_start();
include_once Application::$ROOT_DIR."/views/layouts/$layoutName.php";
$layoutContent = ob_get_clean();
return str_replace('{{content}}', $viewContent, $layoutContent);
}
public function renderViewOnly($view, array $params)
{
foreach ($params as $key => $value) {
$$key = $value;
}
ob_start();
include_once Application::$ROOT_DIR."/views/$view.php";
return ob_get_clean();
}
}