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);
}
BenMorel
  • 30,280
  • 40
  • 163
  • 285
  • 8
    Now beta, report the missing feature (or faulty implementation) ;) – hakre Oct 13 '11 at 11:50
  • 1
    I'd like to be sure that it's not already possible, before writing a feature request :) – BenMorel Oct 13 '11 at 12:13
  • 7
    try `` (at least in extbase this should be possible) – konsolenfreddy Oct 18 '11 at 18:28
  • Have you tried a DTO? – thicolares Jan 20 '14 at 17:08
  • @colares How would a DTO help here? – BenMorel Jan 20 '14 at 17:26
  • 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. – thicolares Jan 20 '14 at 18:30
  • 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! – BenMorel Jan 20 '14 at 19:31

2 Answers2

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

0

remove the word array before $tags

Shinto Joseph
  • 939
  • 7
  • 8