diff --git a/kernel/CgView.php b/kernel/CgView.php index 792c540..3057293 100644 --- a/kernel/CgView.php +++ b/kernel/CgView.php @@ -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 .= ""; + } + + 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(); diff --git a/kernel/admin_themes/default/layout/main.php b/kernel/admin_themes/default/layout/main.php index 5864fb1..db00106 100644 --- a/kernel/admin_themes/default/layout/main.php +++ b/kernel/admin_themes/default/layout/main.php @@ -2,15 +2,18 @@ /** * @var $content * @var string $resources + * @var string $title + * @var \kernel\CgView $view */ \Josantonius\Session\Facades\Session::start(); ?> - Sidebar 01 + <?= $title ?> + getMeta() ?> diff --git a/kernel/modules/post/views/index.php b/kernel/modules/post/views/index.php index 906528a..045feb1 100644 --- a/kernel/modules/post/views/index.php +++ b/kernel/modules/post/views/index.php @@ -3,6 +3,7 @@ /** * @var \Illuminate\Database\Eloquent\Collection $contents * @var int $page_number + * @var \kernel\CgView $view */ use kernel\modules\post\models\Post; @@ -21,6 +22,11 @@ $table = new ListEloquentTable(new EloquentDataProvider(Post::class, [ 'baseUrl' => "/admin/post" ])); +$view->setTitle("Список постов"); +$view->setMeta([ + 'description' => 'Список постов системы' +]); + $entityRelation = new \kernel\EntityRelation(); $additionals = $entityRelation->getEntityRelationsBySlug("post");