Implement simple PHP based view renderer

This commit is contained in:
Tim
2023-08-15 03:02:55 +02:00
parent 9b8985640c
commit c80dcd2860
9 changed files with 83 additions and 9 deletions

View File

@ -7,6 +7,8 @@ use Ardent\Undercurrent\Http\GenericResponse;
use Ardent\Undercurrent\Http\ResponseInterface;
use Ardent\Undercurrent\Http\RouterConfig;
use Ardent\Undercurrent\Http\StatusEnum;
use Ardent\Undercurrent\View\BaseView;
use Ardent\Undercurrent\View\ViewInterface;
class HelloWorldController
{
@ -28,6 +30,12 @@ class HelloWorldController
return new GenericResponse('Hello World!');
}
#[Route('/view')]
public function view(): ViewInterface
{
return new BaseView('/Template/home.php', ['message' => 'Hello World!']);
}
#[Route('/routes/{word}')]
public function routes(RouterConfig $config, string $word): ResponseInterface
{

10
app/Template/base.php Normal file
View File

@ -0,0 +1,10 @@
<?php /** @var $this \Ardent\Undercurrent\View\BaseView */ ?>
<html>
<head>
<title>TOSTI MAN KOMT JE HALEN</title>
</head>
<body>
<?= $this->data['slot'] ?>
</body>
</html>

4
app/Template/home.php Normal file
View File

@ -0,0 +1,4 @@
<?php /** @var $this \Ardent\Undercurrent\View\BaseView */ ?>
<?php $this->extends = '/Template/base.php' ?>
<?= $this->data['message'] ?>