[TYPO3-mvc] Problem calling a repository function
Bastian Waidelich
bastian at typo3.org
Mon Jan 31 12:38:42 CET 2011
Bastian Waidelich wrote:
>> I can't get the objectManager in a render function of a view helper?
>> [...]
>> $projectRepository =
>> $this->objectManager->get('Tx_UtekReferenzen_Domain_Repository_ProjectRepository');
>>
>> Gives an exception that I try to call a member function on a
>> non-object.
>
> Have a look at
> <http://forge.typo3.org/projects/typo3v4-mvc/wiki/Dependency_Injection_%28DI%29#Creating-Prototype-Objects-through-the-Object-Manager>
BTW: you can of course inject the repository directly:
/**
* @var Tx_UtekReferenzen_Domain_Repository_ProjectRepository
**/
protected $projectRepository;
/**
* @param Tx_UtekReferenzen_Domain_Repository_ProjectRepository
$projectRepository
* @return void
**/
public function
injectProjectRepository(Tx_UtekReferenzen_Domain_Repository_ProjectRepository
$projectRepository) {
$this->projectRepository = $projectRepository;
}
HTH
Bastian
More information about the TYPO3-project-typo3v4mvc
mailing list