website/src/Controller/DefaultController.php
Jeroen De Meerleer 563c97925f
Refactor service and controller code, update file paths
- Refactored the `Page` class from the `App\Repository` namespace to the `App\Service` namespace.
- Updated the file path references in the `getPage()` method of the `Page` class to use `$this->kernel` instead of `$kernel`.
- Renamed the file from `src/Repository/Page.php` to `src/Service/Page.php`.
- Updated the import statement in the `DefaultController.php` file to reflect this change.

This commit improves code organization and ensures that file paths are correctly referenced.
2023-10-13 09:22:40 +02:00

28 lines
968 B
PHP

<?php
namespace App\Controller;
use App\Service\Page;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class DefaultController extends AbstractController
{
#[Route('/{slug}', name: 'default', requirements: ['slug' => '[a-zA-Z0-9\/]+'])]
public function DefaultAction(Page $page, string $slug = 'index')
{
$return = $page->getPage($slug);
$response = new Response('', (int)$return['status']);
return $this->render('/page.html.twig', $return, $response);
}
#[Route('/error/{status}', name: 'error', requirements: ['status' => '[0-9]{3}'], priority: 2)]
public function ErrorAction(Page $page, string $status = '404')
{
$return = $page->getPage('error/' . $status);
$response = new Response('', (int)$status);
return $this->render('/page.html.twig', $return, $response);
}
}