Jeroen De Meerleer
563c97925f
- 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.
28 lines
968 B
PHP
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);
|
|
}
|
|
}
|