src/Controller/BlogController.php line 24
<?php
namespace App\Controller;
use App\Services\DbBlog;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class BlogController extends AbstractController
{
#[Route(
path: ['fr' => '/{_locale}/blog/{link}-{id}', 'en' => '/{_locale}/blog/{link}-{id}'],
name: 'blog_content',
requirements: [
'_locale' => 'en|fr',
'link' => '.+?(?=-(b|c)\d{1,4}$)',
'id' => '(b|c)\d{1,4}'
],
priority: 2
)]
public function blog_content(Request $request, DbBlog $dbBlog, $link = null, $id = null): Response
{
$contents = $dbBlog->getContent($link, $request->getLocale());
$link = $dbBlog->getLink($contents[0]['id_leoblog_blog'], $request);
$breadcrumb = array(['name' => 'Blog', 'link_rewrite' => 'blog'], ['name' => $contents[0]['catTitle'], 'link_rewrite' => $contents[0]['catLink']."-c".$contents[0]['id_leoblogcat']]);
return $this->render('blog/blogcontent.html.twig', ['contents' => $contents, 'link' => $link, 'breadcrumb' => $breadcrumb]);
}
#[Route(path: '/{_locale}/blog', name: 'blog', priority: 3)]
public function blog(Request $request, DbBlog $dbBlog): Response
{
$contents = "";
$altLang = $request->getLocale() == "fr" ? "en" : "fr";
$endUrl = $this->generateUrl('blog', ["_locale" => $altLang]);
$menus = $dbBlog->getMenu($request->getLocale());
$cards = $dbBlog->getCard($request->getLocale());
$breadcrumb = array(['name' => 'Blog', 'link_rewrite' => 'blog']);
return $this->render('blog/blog.html.twig', ['cards' => $cards, 'link' => $endUrl, 'menus' => $menus, 'breadcrumb' => $breadcrumb ]);
}
}
?>