microserviciile de register, login finalizate
This commit is contained in:
Regular → Executable
+44
-44
@@ -1,45 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace app\core;
|
||||
|
||||
class View{
|
||||
public string $title = '';
|
||||
|
||||
protected function layoutContent()
|
||||
{
|
||||
$layout = Application::$app->layout;
|
||||
if (Application::$app->controller) {
|
||||
$layout = Application::$app->controller->layout;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
include_once Application::$ROOT_DIR . "/views/layouts/$layout.php";
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
||||
public function renderView($view, $params = [])
|
||||
{
|
||||
$viewContent = $this->renderOnlyView($view, $params);
|
||||
$layoutContent = $this->layoutContent();
|
||||
|
||||
return str_replace('{{content}}', $viewContent, $layoutContent);
|
||||
}
|
||||
|
||||
public function renderContent($viewContent)
|
||||
{
|
||||
$layoutContent = $this->layoutContent();
|
||||
return str_replace('{{content}}', $viewContent, $layoutContent);
|
||||
}
|
||||
|
||||
protected function renderOnlyView($view, $params)
|
||||
{
|
||||
foreach ($params as $key => $value) {
|
||||
$$key = $value;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
include_once Application::$ROOT_DIR."/views/$view.php";
|
||||
return ob_get_clean();
|
||||
}
|
||||
<?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;}
|
||||
}
|
||||
Reference in New Issue
Block a user