[TYPO3-mvc] Dependeny Injection in Model class not working?
Matthias Krappitz
matthias at nospam.aemka.de
Sun Aug 14 16:03:02 CEST 2011
Hi,
in one project I need to dynamically query something using a repository in a
model class (I need a getter for the subcatgories of a category). Is
dependency injection as it is working in controller classes also thought for
model classes in this case? At least this code, that works in my controller
class is not working in one of my model classes, $this->categoryRepository
stays NULL:
/**
* categoryRepository
*
* @var Tx_Travel_Domain_Repository_CategoryRepository
*/
protected $categoryRepository;
/**
* injectCategoryRepository
*
* @param Tx_Tavel_Domain_Repository_CategoryRepository $categoryRepository
* @return void
*/
public function
injectCategoryRepository(Tx_Dedontravel_Domain_Repository_CategoryRepository
$categoryRepository) {
$this->categoryRepository = $categoryRepository;
}
Is there anyhing I need to do for this to work or is this just not
implemented and I need to do it another way? If yes, how?
t3lib_div::makeInstance()? Object Manager?
Another question concerning this to broaden my general understanding on
this - in the controller classes is dependency injection like shown above
THE way to go for all occasions of requiring a instanciated object? Or when
should I still use $this->objectManager->... or is this deprecated now? I
suppose t3lib_div::makeInstance() and new somehting (); is both absolutely
never not meant to be used any more.
Matthias Krappitz
w. www.aemka.de
More information about the TYPO3-project-typo3v4mvc
mailing list