[TYPO3-mvc] Dependency Injection fails only in models

Christian Peters chp at digitale-avantgarde.com
Thu Mar 22 14:32:23 CET 2012


Alright, that was maybe too obvious ...

Coming from TYPO3, i was used initiating objects via "new"; which is not
supported by Extbase.

The object manager works like a charm :)


*One final question: *Does dependency injection work, if I receive Models
through a Repository?

@Frank: How would you suggest to solve the described problem, if you do
recommend to not use repositories in models (you have a point there)

Thanks for your help!



2012/3/22 Christian Peters <chp at digitale-avantgarde.com>

> Thanks,
>
> I have the latest extbase version.
>
> To your btw: My model retrieves data from an external service that may
> send duplicate entries. Before a model creates a new Model as child in it's
> setter, it checks if it already exists (with a findByMd5Hash() method).
>
> I'm happy to discuss if this is a cool method, or if this check is
> something that the controller should take care of.
>
> However, at the moment the dependency injection does not work - neither
> with repositories nor with other Classes.
>
> Best
> Chris
>
>
>
> 2012/3/22 Frank Gerards <F.Gerards at esolut.de>
>
>> Hi,
>>
>> afaik only latest extbase version allows DI in models.
>>
>> Btw. Why would you want to insert a Repo in a model ? Seems like hurting
>> the MVC concept ...
>>
>> Greetz,
>> Frank
>>
>> -----Ursprüngliche Nachricht-----
>> Von: typo3-project-typo3v4mvc-bounces at lists.typo3.org [mailto:
>> typo3-project-typo3v4mvc-bounces at lists.typo3.org] Im Auftrag von
>> Christian Peters
>> Gesendet: Donnerstag, 22. März 2012 10:17
>> An: typo3-project-typo3v4mvc at lists.typo3.org
>> Betreff: [TYPO3-mvc] Dependency Injection fails only in models
>>
>> Hello y'all,
>>
>> I'm working on an extbase extension. I have some experience with flow but
>> little with typo3 and extbase.
>>
>> However, I want to inject a repository in my model and it simply does not
>> work: The inject*() function does not get called. The code is copied from
>> a controller.
>>
>> The injection works in the controller, but not in the models. This is my
>> code:
>>
>>
>> /**
>>         * imageRepository
>>         *
>>         * @var Tx_MeineExtension_Domain_Repository_ImageRepository
>>         */
>>        protected $imageRepository;
>>
>>        /**
>>         * injectImageRepository
>>         *
>>         * @param Tx_MeineExtension_Domain_Repository_ImageRepository
>> $imageRepository
>>         * @return void
>>         */
>>        public function
>> injectImageRepository(Tx_MeineExtension_Domain_Repository_ImageRepository
>> $imageRepository) {
>>                die('This was called.');
>>                $this->imageRepository = $imageRepository;
>>        }
>>
>>
>> No errors, no clues. the inject* is simply not getting called.
>>
>> I receive lot's of extbase / typo3 extmanager / typo3 persistence etc.
>> Notices when I turn E_ALL | E_STRICT on.
>>
>> Among them:
>>
>>
>> Notice: Undefined index: Tx_MyExtension_Domain_Model_UserModel in
>> C:\xampp\htdocs\t3\typo3\sysext\extbase\Classes\Persistence\Mapper\DataMapFactory.php
>> on line 96
>>
>>
>>
>>
>> Notice: Undefined index: tx_bphilcore_UserModel_image_mm in
>> C:\xampp\htdocs\t3\typo3\sysext\extbase\Classes\Persistence\Mapper\DataMapFactory.php
>> on line 152
>>
>>
>>
>> UserModel is my model that get's the imageRepository injected.
>>
>> I have tried very much and am down to my last now. Has anyone a clue what
>> I can try next?
>>
>> Caches are flushed.
>>
>> Thank you for your help.
>>
>> Chris
>> _______________________________________________
>> TYPO3-project-typo3v4mvc mailing list
>> TYPO3-project-typo3v4mvc at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>> _______________________________________________
>> TYPO3-project-typo3v4mvc mailing list
>> TYPO3-project-typo3v4mvc at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>>
>>
>


More information about the TYPO3-project-typo3v4mvc mailing list