sulu-workshop
sulu-workshop copied to clipboard
12 - Add a location filter to the events overview page
Add a location filter to the events overview page
Goal
After adding an association between our Location
entity and our Event
entity in the last assignment, we can
now easily query events for a specific location. We want to make use of this by adding a location filter to the
events overview page of our website.
Steps
- Create a new content controller
App\Controller\EventOverviewController
- Remove the
events
property from theevent_overview
template - Use the newly created
App\Controller\EventOverviewController
in yourevent_overview
template - Use the
EventRepository
to load events in yourEventOverviewController
- Use the
LocationRepository
to load locations in yourEventOverviewController
- Pass the loaded locations and events to your Twig template
- Render a form with a location dropdown in your
templates/events/index.html.twig
- Add a
filterByLocationId
method to yourApp\Repository\EventRepository
- Call the
filterByLocationId
method with the submitted value in yourEventOverviewController
Hints
More Information
Links
- Source file of this assignment: assignments/12.md
Guys, is this supposed to work properly because I cannot get it to work at all and I am an experienced dev. I tried this https://docs.sulu.io/en/2.4/cookbook/custom-controller.html but to no avail and am getting Cannot autowire argument $structure of "App\Controller\Website\EventOverviewController::indexAction()": it references interface "Sulu\Component\Content\Compat\StructureInterface" but no such service exists. Did you create a class that implements this interface?
@costeaalex the Structure
is no service this is a request attribute set by the content route provider. The error you are experience is mostly done if you try to register a route for a content controller, but content controller do not have a route as they are called by the dynamic route provider, which calls the controller based on saved pages and the pages template.
@costeaalex the
Structure
is no service this is a request attribute set by the content route provider. The error you are experience is mostly done if you try to register a route for a content controller, but content controller do not have a route as they are called by the dynamic route provider, which calls the controller based on saved pages and the pages template.
I figured it out eventually, thanks. I think what would be helpful though is to offer the preferred solution to these problems as well so that people less experienced manage to get through it in a reasonable time span ;). Thanks for the input. You will probably be hearing from me for some consultancy and if we adopt the CMS we will contribute :P.
@costeaalex If there is anything we can improve in the documentation, we are happy for any pul request there: https://docs.sulu.io/en/2.4/cookbook/custom-controller.html. Happy to hear you give sulu a try, you can reach us over our website or our slack channel for any questions.