Add a second model and repository

In this part we don’t learn anything new, but it is required to have it for the next step. So normally an event has some location where the event takes place. So we create a new model called Location and the corresponding repository called LocationRepository.

The location model

For now we keep it simple, so all we need for now for the location model is the title for the location.

So build the model, it will look similar to the event model. Add the getter and setter functions and don’t forget to set the annotations.

Generate the model


The location repository

If you have any problems with this part, check back on the part where we create the repository for the events. It is exactly the same here.

Generate your repository

 Creating the rest of the files required

At this point we have to do some more work. Now we do the same stuff we have done for the events for the locations. We add a action to display a form, we use this form to add locations, and we add the action to save the locations.

Create the LocationController

 The templates

Now we have to create two templates. One for the indexAction and one for the addAction.

 Updating Routes.yaml

Since we have a new Controller now, we add this controller to the Routes.yaml to have some nice URLs.

Modifiy your Routes.yaml so that it looks like below. We add the new routes for the locationController at the top.


Leave a Reply

Your email address will not be published. Required fields are marked *