[TYPO3-mvc] Re: Get RepositoryName from ModelName
Philipp
philippwrann at gmx.at
Tue Mar 12 13:57:14 CET 2013
Didnt find any method, so i wrote this workaround.
/**
* Get an object by uid
* @param int $uid The uid
* @param string $object The objectName
* @return mixed Object from class of $object | NULL if not found
*/
protected function getPersistentObject($uid,$object) {
if (class_exists($object)) {
$repositoryName = str_replace('Model','Repository',$object).'Repository';
if (class_exists($repositoryName)) {
/* @var $repository \TYPO3\CMS\Extbase\Persistence\Repository */
$repository = $this->objectManager->get($repositoryName);
return $repository->findByUid($uid);
}
}
return NULL;
}
You can call it like this in your controller
$something = $this->getPersistentObject(someParam,'Vendor\\ExtensionName\\Domain\\Model\\SomeObject');
Not really the big deal but avoids much typing.
More information about the TYPO3-project-typo3v4mvc
mailing list