[TYPO3-mvc] initializeObject() pointless?
Martin Kutschker
masi-no at spam-typo3.org
Thu Jun 10 21:01:17 CEST 2010
roberto blanko schrieb:
> Damn, not good. Thanks for you answer anyway.
>
> What I need to do: Right after the object was mapped with its properties
> from the DB I need to manipulate the attributes before the object (e.g.
> using a getter call) is accessed for the first time.
>
> I haven't actually found a usable workaround yet. What I'm doing right now
> is calling my initialize-method manually before I'm accessing the
> attributes. Which isn't very nice especially through Fluid, since I need a
> special ViewHelper to call the method. Calling the method manually in the
> controller is not an option (architectural reasons).
What I do is this (in my model):
/**
* Reconstitutes a property. Only for internal use - but I use it for a hack :)
*
* @param string $propertyName
* @param string $value
* @return bool
*/
public function _setProperty($propertyName, $propertyValue) {
// The data mapper doesn't know about this property type so we thaw it ourself.
if ($propertyName == 'myproperty') {
$this->myproperty = 'something like that';
return TRUE;
} else {
return parent::_setProperty($propertyName, $propertyValue);
}
}
Important:
In case you want to use an object, it's __toString() method must return the value as it is to be
stored in the DB. Otherwise you will not be able to persist it correctly.
Masi
More information about the TYPO3-project-typo3v4mvc
mailing list