cg view title, meta

This commit is contained in:
2024-12-12 14:06:47 +03:00
parent f7253bafe9
commit 9c77403a71
3 changed files with 37 additions and 3 deletions

View File

@ -10,6 +10,8 @@ class CgView
public array $varToLayout = [];
public bool|string $layout = false;
protected array $metaArr = [];
public function __construct()
{
@ -34,14 +36,37 @@ class CgView
$this->varToLayout[$key] = $value;
}
private function createContent(string $view, array $data = []): false|string
public function setTitle(string $title): void
{
$this->addVarToLayout('title', $title);
}
public function setMeta(array $meta): void
{
foreach ($meta as $key => $value){
$this->metaArr[$key] = $value;
}
}
public function getMeta(): string
{
$meta = "";
foreach ($this->metaArr as $key => $value){
$meta .= "<meta name='$key' content='$value'>";
}
return $meta;
}
private function createContent(string $viewFile, array $data = []): false|string
{
ob_start();
$view = $this;
foreach ($data as $key => $datum) {
${"$key"} = $datum;
}
include($this->viewPath . $view);
include($this->viewPath . $viewFile);
$content = ob_get_contents();
ob_end_clean();