[TYPO3-mvc] [Extbase] Object doesn't get initialized.
Franz Koch
typo3.RemoveForMessage at elements-net.de
Thu Oct 14 11:00:10 CEST 2010
Hey,
> main_domain_model -(m:n)-> user -(1:n)-> item
>
> In my user model I initialize the items:
>
> class Tx_MyExt_Domain_Model_User extends
> Tx_Extbase_Domain_Model_FrontendUser {
>
> /**
> * @var Tx_Extbase_Persistence_ObjectStorage<Tx_MyExt_Domain_Model_Item>
> The items of a user
> **/
> protected $items;
>
> /**
> * Constructor
> **/
> public function __construct() {
> $this->items = new Tx_Extbase_Persistence_ObjectStorage;
> }
>
> ...
>
> /**
> * Returns the items of the user
> *
> * @return
> Tx_Extbase_Persistence_ObjectStorage<Tx_MyExt_Domain_Model_Item> The
> items of the user
> **/
> public function getItems() {
> return clone $this->items;
> }
>
> ...
>
> }
do you also have a setter method? If not, add it and see if your issue
is gone (which it should).
...
> However I get the error "Fatal error: __clone method called on non-object
> in ..." when for example the $user->getItems Method gets called during
> operation.
>
> The 'items' attribute is somehow not initialized and it is set to 'NULL'.
>
> I have no clue about how to trace this error down. I would highly
> appreciate if somebody could help me out with a hint on where the problem
> could actually be. Is there a general mistake I might have made here?
IIRC extbase is only calling the constructor on new objects - but not
objects that get reconstituted from database (which could create wrong
parameters somehow).
--
kind regards,
Franz Koch
More information about the TYPO3-project-typo3v4mvc
mailing list