Compare commits

..

2 Commits

Author SHA1 Message Date
408cc0d88a ConferenceRepository uses custom sorting 2024-07-28 00:57:54 -04:00
edda567057 Implement site-wide page header 2024-07-28 00:55:18 -04:00
3 changed files with 47 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
<?php
namespace App\EventSubscriber;
use App\Repository\ConferenceRepository;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Twig\Environment;
class TwigEventSubscriber implements EventSubscriberInterface
{
private $twig;
private $conferenceRepository;
public function __construct(Environment $twig, ConferenceRepository $conferenceRepository)
{
$this->twig = $twig;
$this->conferenceRepository = $conferenceRepository;
}
public function onControllerEvent(ControllerEvent $event): void
{
$this->twig->addGlobal('conferences', $this->conferenceRepository->findAll());
}
public static function getSubscribedEvents(): array
{
return [
ControllerEvent::class => 'onControllerEvent',
];
}
}

View File

@@ -16,6 +16,12 @@ class ConferenceRepository extends ServiceEntityRepository
parent::__construct($registry, Conference::class); parent::__construct($registry, Conference::class);
} }
public function findAll(): array
{
// Override findAll() to use custom sorting
return $this->findBy([], ['year' => 'ASC', 'city' => 'ASC']);
}
// /** // /**
// * @return Conference[] Returns an array of Conference objects // * @return Conference[] Returns an array of Conference objects
// */ // */

View File

@@ -12,6 +12,15 @@
{% endblock %} {% endblock %}
</head> </head>
<body> <body>
<header>
<h1><a href="{{ path('homepage') }}">Guestbook</a></h1>
<ul>
{%for conference in conferences %}
<li><a href="{{ path('conference', { id: conference.id }) }}">{{ conference }}</a></li>
{% endfor %}
</ul>
<hr/>
</header>
{% block body %}{% endblock %} {% block body %}{% endblock %}
</body> </body>
</html> </html>