HEX
Server: Apache
System: Linux WWW 6.1.0-40-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.153-1 (2025-09-20) x86_64
User: web11 (1011)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: /var/www/dvpis2026/dvpis.kaunokolegija.lt/src/Controller/DefaultController.php
<?php

namespace App\Controller;

use App\Entity\Blog;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

class DefaultController extends AbstractController
{
    #[Route(path: '/', name: 'homepage')]
    public function indexAction(Request $request, EntityManagerInterface $entityManager)
    {

        $blogs = $entityManager->getRepository(Blog::class)->findActive();

        return $this->render('default/index.html.twig', [
            'base_dir' => realpath($this->getParameter('kernel.project_dir')) . DIRECTORY_SEPARATOR,
            'role' => $this->getUser()?->getRole(),
            'blogs' => $blogs,
        ]);
    }

    #[Route(path: '/set-locale/{locale}', name: 'change_locale')]
    public function setLocale(Request $request, string $locale): RedirectResponse
    {

        if (in_array($locale, ['en', 'lt'])) {
            $request->getSession()->set('_locale', $locale);
            $request->setLocale($locale);
        }

        return $this->redirectToRoute('homepage');
    }
}