[TYPO3-mvc] How to extend a model class from within another extension?

Franz Koch typo3.RemoveForMessage at elements-net.de
Mon Jan 18 00:18:06 CET 2010


Hi,

> do you mean overwriting the model class magic __set and __get methods,
> calling the parent methods, and if nothing was returned, implement a
> custom routine, to fetch fields of the TCA?

Maybe something like this (untested):

public function __call($methodName, $arguments) {
	if (substr($methodName, 0, 3) === 'get' && strlen($methodName) > 4 && 
!method_exists(get_class($this),$methodName)) {
		$propertyName = strtolower(substr($methodName, 3));
		t3lib_div::loadTCA('###YOUR_TABLE_NAME###');
		if($GLOBALS['TCA']['###YOUR_TABLE_NAME###']['columns'][$propertyName]) {
			return $this->$propertyName;
		}
	} elseif (substr($methodName, 0, 3) === 'set' && strlen($methodName) > 
4 && !method_exists(get_class($this),$methodName)) {
		$propertyName = strtolower(substr($methodName, 3));
		t3lib_div::loadTCA('###YOUR_TABLE_NAME###');
		if($GLOBALS['TCA']['###YOUR_TABLE_NAME###']['columns'][$propertyName]) {
			$this->$propertyName = $arguments[0];
		}
	} else {
		throw new Tx_Extbase_Persistence_Exception_UnsupportedMethod('The 
method "' . $methodName . '" is not supported by this controller.', 
1233180480);
	}
}


It's just a basic example. But I fear that extbase won't fill the model 
with the new db-fields as the classVars are not declared - but maybe I'm 
wrong.
-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list