File: /var/www/dvpis2025/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');
}
}