[FLOW3-general] Recursive domain object
Tommy Seus
tommy.seus at gmail.com
Wed Dec 16 16:23:50 CET 2009
Have you created the object in the constructor?
__construct() {
$this->items = new \SplObjectStorage;
}
Am 16.12.2009 16:17, schrieb Rens Admiraal:
> I have a menuitem object in my domain model, and I want it to be
> recursive so menuitems can hold subitems.
> I've tried this to add the following variable / method:
>
> /**
> * @var \SplObjectStorage<\F3\Package\Domain\Model\MenuItem>
> * @lazy
> */
> protected $items;
>
> /**
> * @param \F3\Package\Domain\Model\MenuItem $item
> * @return void
> */
> public function addMenuItem(\F3\Package\Domain\Model\MenuItem $item) {
> $item->setParent($this); // setter for parent property of
> type \F3\Package\Domain\Model\MenuItem
> $this->items->attach($item);
> }
>
>
> But when I call the method addMenuItem on an object I get 'Call to a
> member function attach() on a non-object in.... on line ...', in which
> the linenumber points to the addMenuItem method...
>
> What's the right way to create a recursive object?
>
>
> With kind regards,
> Rens Admiraal
> TYPO3 Certified Integrator
>
> _______________________________________________
> FLOW3-general mailing list
> FLOW3-general at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow3-general
More information about the FLOW3-general
mailing list