简体   繁体   中英

Typo3 (6.2.4) Extbase / Fluid / Error Handling: Strange index of related objects

I've got an object "Laeufer" which can have "Sponsoren" (1:n). For the "Sponsoren" I've got different required input fields like

<input class="form-control sponsorBetrag" name="tx_lhsponsorenlauf_p1registrierung[laeufer][sponsoren][0][betrag]" type="text">

But when I submit the form, the property path looks like sponsoren.00000000497382d100007fe050b66fc0.betrag not sponsoren.0.betrag which would I expect. As well the field not getting the error class "myerror". Any ideas?

FLUID

<f:form.textfield errorClass="myerror" property="sponsoren.0.betrag" class="form-control sponsorBetrag" />

You most likely used \\TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage for your property. This is similar to the \\SplObjectStorage and does not use numeric indexes for the internal storage array, but hashes the objects it is going to store and uses this hashed object as index for it. You can however work around that and use $this->view->assign('sponsoren', $sponsoren->toArray()); in your controller to assign a real array to your view, instead of the ObjectStorage.

Second, your field isn't getting the error class, because you do not use a ViewHelper. Therefore Fluid doesn't care about your input at all. I would suggest to use <f:form.textfield property="betrag" /> in your template instead of a self-written input.

EDIT:

As far as I know, the usage of an OjectStorages Sub-Property as a distinct field, instead of having a select field, is not possible with TYPO3 6.2. It may be, that your Domain Model Architecture is wrong though, if you need to have form fields for distinct elements of your ObjectStorage. If you have a sponsor-object that is a specific one, you should use a distinct property for this one, instead of have it in a list of sponsors.

If you want to have an edit form for single sponsors, do it like this

<f:for each="{sponsors}" as="sponsor">
    <f:form action="update" controller="Sponsor" object="{sponsor}" name="sponsor">
        <f:form.textfield property="betrag" errorClass="myerror" class="form-control sponsorBetrag" />
    ...
        <f:form.submit value="Update sponsor" />
    </f:form>
</f:for>

and create a controller that can update single sponsors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM