first commit
This commit is contained in:
59
core/cg_view/CgView.php
Normal file
59
core/cg_view/CgView.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace itguild\forms\form\core\cg_view;
|
||||
|
||||
class CgView
|
||||
{
|
||||
public string $viewPath = '';
|
||||
public bool|string $layout = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function render(string $view, array $data = []): void
|
||||
{
|
||||
$content = $this->createContent($view, $data);
|
||||
|
||||
echo $content;
|
||||
}
|
||||
|
||||
public function fetch(string $view, array $data = []): false|string
|
||||
{
|
||||
$content = $this->createContent($view, $data);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
private function createContent(string $view, array $data = []): false|string
|
||||
{
|
||||
ob_start();
|
||||
|
||||
$cgView = new self();
|
||||
$cgView->viewPath = $this->viewPath;
|
||||
|
||||
foreach ($data as $key => $datum){
|
||||
${"$key"} = $datum;
|
||||
}
|
||||
|
||||
include ($this->viewPath . $view);
|
||||
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean ();
|
||||
|
||||
ob_start();
|
||||
$file_content = $content;
|
||||
|
||||
if ($this->layout){
|
||||
if (file_exists($this->viewPath . $this->layout)){
|
||||
include ($this->viewPath . $this->layout);
|
||||
$file_content = ob_get_contents();
|
||||
}
|
||||
}
|
||||
ob_end_clean ();
|
||||
|
||||
return $file_content;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user