[TYPO3-mvc] Get repository object from table name
Thomas "Thasmo" Deinhamer
thasmo at gmail.com
Thu Jan 27 14:38:24 CET 2011
Franz Koch wrote:
> sorry, I added the first line from my mind.
No problem, you took me on the right path.
Nevertheless I think TYPO3/t3lib_div misses
a function for doing this at a central place.
What I did is this (shortened):
class Tx_Ext_Persistence_RepositoryFactory implements t3lib_singleton {
public static function createByTableName($tableName) {
$modelClassName = str_replace(' ', '_', ucwords(str_replace('_', ' ',
t3lib_div::strtolower($tableName))));
$repositoryClassName = str_replace('_Model_', '_Repository_',
$modelClassName) . 'Repository';
return t3lib_div::makeInstance($repositoryClassName);
}
public static function createByRecordName($recordName) {
$tableName = implode('_', explode('_', $recordName, -1));
return self::createByTableName($tableName);
}
}
Regards,
Thomas
More information about the TYPO3-project-typo3v4mvc
mailing list