If this tutorial is helpful to you, you can donate some money to the tutorial author via Paypal.

FLOW3, similar to extbase has a nice way to add object with forms. In this part we just build a simple form to add some more events.

Extend the EventController

First we add a new action to our eventController. The action has not much to do. It should only display the form.

Basically this action could be also empty. It would be enough to display the form. We inject an event object here, because if the form-validation fails, the event object will be submitted back to the action. This is also the reason that we tell the action that it should not validate the object. We do this by adding the annotation @dontvalidate.

Then we assign the object, that is either null or returned by the form to the view. If it is returned by the view, we have at least the successful validated properties available and can display this properties in the form again.

 * newAction
 * this action will only load the template and display the
 * form for adding a new event
 * @return void
public function newAction() {

The form

Create the file and remember that the naming is important, so that FLOW3 can automatically find the correct template.

The template is pretty much straight forward. We tell Fluid about the layout file, the same we used before. Inside the div-container we add the form using the f:form ViewHelper provided by Fluid.

Adding the action is not new to us. The interesting part here is, that we tell the form that it should handle the object "event".

The next line is the text box where we can enter the event title. Here we tell FLOW3/Fluid that the title is a property. This way FLOW3/Fluid knows that the title is a property of the object event.

There is also a ViewHelper for the submit button. Add it before you close the form.


<f:layout name="Index.html" />
<f:section name="content">
    <h1>FLOW3 Tutorial adding an Event</h1>
    <div id="content">
        <f:form action="create" controller="Event" package="Layh.Events" name="event" object="{event}">
            <label for="title">Title:</label><f:form.textbox id="title" property="title" /><br />
            <f:form.submit value="Save" />

Save the object

Last part here is to save the object after we submit the form. We need another action in our controller. Like the action we defined in the form, we call the action createAction and add it to our controller.

The EventRepository is already available. We added it to our IndexController before and used the @inject annotation to make it available.

So all we have to do here, add the event-object as parameter to your function and add it to your repository using the add-function that is already available. If you check your database now, or if you call the listAction, you should be able to see your new object.

The last line redirect directly to the listAction. In this case we don't need a template for the saveAction. But you can also add a Save.html template with some kind of information if the object was saved successfully.

Currently we don't use any validation here, we add this later.

 * @param \Layh\Events\Domain\Model\Event $events
 * @return void
public function createAction(\Layh\Events\Domain\Model\Event $event) {

Was this tutorial helpful? So, you can donate some money to the tutorial author via Paypal.