Files
FACULTATE-KNOW_YOUR_FOOD/knowyourfood/core/View.php
T

45 lines
1.5 KiB
PHP
Executable File

<?php
namespace app\core;
class View{
private string $title = '';
private string $view = '';
private string $layout = 'main';
private ?Model $model = NULL;
private string $actionError = '';
public function render(): string
{
$viewContent = $this->renderView();
$layoutContent = $this->renderLayout();
return str_replace('{{content}}', $viewContent, $layoutContent);
}
public function renderView(): string
{
ob_start();
include_once Application::$ROOT_DIR . "/views/$this->view.php";
return ob_get_clean();
}
public function renderLayout(): string
{
ob_start();
include_once Application::$ROOT_DIR . "/views/layouts/HTML/$this->layout.php";
return ob_get_clean();
}
public function setLayout($layout): void {$this->layout = $layout;}
public function setTitle($title): void {$this->title = $title;}
public function setView($view): void {$this->view = $view;}
public function setModel(?Model $model): void {$this->model = $model;}
public function setActionError(string $actionError): void {$this->actionError = $actionError;}
public function getTitle(): string {return $this->title;}
public function getView(): string {return $this->view;}
public function getLayout(): string {return $this->layout;}
public function getModel(): ?Model {return $this->model;}
public function getActionError(): string {return $this->actionError;}
}