[FLOW3-general] Constructor injection in models?

Michael Sauter mail at michaelsauter.net
Sat Apr 24 10:28:43 CEST 2010


On 24.04.10 02:06, Tommy Seus wrote:
> I have it read again:)

;) Probably you have to read it one more time. Seems I'm not very good 
at explaining things :)

> I have tested it just with creating a new entity. In my case it worked.
> (2 month old FLOW3)
>
> Alternatively there is the intializeObject() method.

Thanks for the tip, I'll have a look at that! Sounds like a solution to 
me :)

>      /**
>       * @var \F3\Messageboard\Board\Domain\Repository\MessageRepository
>       */
>      protected $messageRepository;
>
>      /**
>       * constructor
>       *
>       * @param \F3\Messageboard\Board\Domain\Repository\MessageRepository
> $messageRepository
>       */
>       public function
> __construct(\F3\Messageboard\Board\Domain\Repository\MessageRepository
> $messageRepository) {
>          $this->messageRepository = $messageRepository;
>          $this->messageRepository->findAll();
>       }

This works as well for me, but not when the object has to be build from 
a form (because there, the constructor arguments are taken from the 
request, and the request does not have a MessageRepository available).

The problem here is more the building process of the controller action 
arguments than the models itself, which are just plain PHP objects 
anyway. But the problem will probably only occur with models, because 
what else needs to be build from forms?

~michael


More information about the FLOW3-general mailing list