FLOW3 action parameters and arrays of objects
Asked Answered
E

2

77

FLOW3 provides a convenient way to pass entities by ID in the URL, and get them automatically instantiated in the controller action's parameters:

class PostController extends \TYPO3\FLOW3\MVC\Controller\ActionController {
    public function editAction(Post $post) {
        ...
    }
}

But what about the use case where you have checkboxes, each representing a particular object? It would be handy to get them autoinstantiated as well:

<input type="checkbox" name="tags[]" value="1" />
<input type="checkbox" name="tags[]" value="2" />
...

Is there a way to tell FLOW3 to auto-instantiate the $tags variable as an array of Tag objects? Something like:

public function setTagsAction(Post $post, /** @var Model\Tag */ array $tags) {
    $post->setTags($tags);
}
Endpaper answered 13/10, 2011 at 11:44 Comment(7)
Now beta, report the missing feature (or faulty implementation) ;)Consalve
I'd like to be sure that it's not already possible, before writing a feature request :)Endpaper
try <input type="checkbox" name="tags[][__identity]" value="1" /> (at least in extbase this should be possible)Impatience
Have you tried a DTO?Beelzebub
@colares How would a DTO help here?Endpaper
Oh, nevermind about about DTO! hehe Post hasMany Tag, right? So you don't need to set a new parameter, all you need to do is to send and get tags as Post's children. Note: there is a trick thing you MUST to do at initializeMyActionNameAction. Are you using Flow 2.0 (they just released 2.1 today) and FLUID? I can post a complete answer.Beelzebub
That's not the point: I want(ed) (this question is more than 2 years old) to auto-instantiate Tags that were not already on Post, but whose IDs were posted in a form. If you have a way to do that with any version of Flow, you're welcome to post an answer!Endpaper
H
2
/**
 * @param Post $post
 * @param \Doctrine\Common\Collections\ArrayCollection<\your\namespace\Model\Tag> $tag
 */

public function setTagsAction(Post $post, $tags) { ...

afaik Doctrine will convert your array to a Collection Holding Objects mapped by the provided array

Hepzi answered 27/11, 2013 at 10:11 Comment(0)
T
0

remove the word array before $tags

Turncoat answered 12/1, 2014 at 4:22 Comment(1)
And how do you specify the class name? Did you try it?Endpaper

© 2022 - 2024 — McMap. All rights reserved.