[TYPO3-mvc] problem with constructor method not called?

Franz Koch typo3.RemoveForMessage at elements-net.de
Thu Jan 7 22:05:04 CET 2010


Hi,

me again. I just stumbled over a strange thing. In my model I have a 
property $contentItems of type Tx_Extbase_Persistence_ObjectStorage. In 
my __construct method of the model, I create a new instance of the class:

public function __construct() {
	$this->contentItems = new Tx_Extbase_Persistence_ObjectStorage();
}


In my function getContentItems I first have to collect the various 
content items and attach them to my property contentItems [1], but if I 
do so I get a php error "Fatal error: Call to a member function attach() 
on a non-object in...". How can this happen?

The debug trace says that the responsible class triggering this should 
be Tx_Extbase_Reflection_ObjectAccess, so I think the reflection magic 
is not running the constructor or whatever. So what do I have to do to 
get it working? I thought it's allowed to fetch some objects inside 
getter methods, and the constructor is like in the blogExample supposed 
to be used for initializing the ObjectStorage instances, right? For now 
I initialize it inside my getter method - but the other way should also 
work I think?

[1]
public function getContentItems() {
	foreach ($this->getArticles() as $object) {
		$this->contentItems->attach($object);
	}
	foreach ($this->getArticleGroups() as $object) {
		$this->contentItems->attach($object);
	}
	return $this->contentItems;
}

-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list