Reputation: 97
I have following relations in my model: Request 1:n Hall (one-to-many)
In Request model class I have
/**
* hall
*
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Vendor\Ext\Domain\Model\Hall>
* @cascade remove
*/
protected $hall = null;
In Hall model class I have
/**
* num
*
* @var string
* @validate NotEmpty
*/
protected $num = '';
Can I set multiple items in one Fluid form? Like
<f:form avction="create" name="hall" object="{hall}" controller="Hall">
<f:form.textfield name="hall[num][]" class="form-control" />
<f:form.textfield name="hall[num][]" class="form-control" />
<f:form.submit value="Create" />
</f:form>
Upvotes: 0
Views: 1000
Reputation: 6460
You are close to the solution, the field name
you wrote is missing the proper plugin namespace however. There is an easier solution for this:
<f:form action="create" name="request" object="{request}" controller="Request">
<f:form.textfield property="hall.0.num" class="form-control"/>
<f:form.textfield property="hall.1.num" class="form-control"/>
<f:form.submit value="Create"/>
</f:form>
It is essential that you create your root entity (request here) with the form and all relations through appropriate form fields. Using property
ensures the proper name (including plugin namespace) for all fields, in this case e.g. name="tx_myext_myplugin[request][hall][0][num]"
.
As you probably noticed you can add as many relation objects as desired as long as you use a numeric index for each object. For many fields you could use the f:for
viewhelper.
Upvotes: 2
Reputation: 2208
I personally struggle with the automapping of typo3 so I would do the following:
add the following funcs to your model
public function addHall(Hall $hall){
$this->hall->atach($hall)
}
pubflic function removeHall(Hall $hall){
$this->hall->detach($hall)
}
Note: Kepp in mind that you have to declare $hall al object storage
Now you can create a new hall object in your controller, persist the new hall, add it with the addHall-method to yor desired model and persist.
Hint: there are nice little functions fpr persisting; similar to PersistanceManager::persistAll() or s.th. like that
Upvotes: 0