[TYPO3-mvc] Get a class' name from a given table name
Dirk Rauscher
dr_typo3 at zolonbow.de
Tue Sep 4 18:47:53 CEST 2012
Hi there,
my question is refering to this thread:
http://lists.typo3.org/pipermail/typo3-project-typo3v4mvc/2011-January/008210.html
I tried to retrieve a class' name from it's related table. Like this:
$class_name = SomeClass::getRelatedClassNameFromTableName($table_name);
The suggested way from Thomas was:
-----------------------------------------------------------------
$modelClassName = str_replace(' ', '_', ucwords(str_replace('_', ' ',
t3lib_div::strtolower($tableName))));
$repositoryClassName = str_replace('_Model_', '_Repository_',
$modelClassName) . 'Repository';
-----------------------------------------------------------------
Unfortunately this solution does not remind that a class' name could
look like this:
-----------------------------------------------------------------
Tx_MyExt_Domain_Model_AnotherClass
-----------------------------------------------------------------
The related tablename would look like this:
-----------------------------------------------------------------
tx_myext_domain_model_anotherclass
-----------------------------------------------------------------
Now when I use Thomas' suggested code the resulting class name would be
this:
-----------------------------------------------------------------
Tx_Myext_Domain_Model_Anotherclass
-----------------------------------------------------------------
which obviously is wrong.
Now, is there an option to retrieve the related class name from it's
related table's name? May be by the DataMapper class?
Best regards,
Dirk
More information about the TYPO3-project-typo3v4mvc
mailing list