[TYPO3-mvc] How to add a unique/primary key property to a manually created domain model?

Jan Kornblum jan.kornblum at gmx.de
Sat Feb 16 02:47:01 CET 2013


Hi again,

some more explanations about this (i hope i don't get on your nerves):

> how can i add  "unique/primary/required"-like property to a manually created 
> domain model. the model was not created using extensionbuilder and the model 
> doesn't own a underlaying database.
>
> The domain model extends AbstractEntity, and when i vardump the object i see 
> that there is a uid, but it is NULL.
>
> Do i have to implement the unique/primary/required logic myself or can this 
> be done by any @validate oder similar notations?

Is it possible at all to automatically give non-database-persistable 
objects an identity, like they were real db-persistable objects? In my 
case these objects are session-stored BasketItems and i want to use 
their identity to access / restore the objects in controller actions 
(show/remove/etc).

Another approach i've tried was to store ProductModel objets itself 
into a fe_user-session-stored BasketObject. Adding products works fine, 
showing the baskets items and other things also, but i'm not able to 
remove products.

When i call $this->products->detach($product) it seems that the 
$product passed as param to the method cannot be found in 
$basket->products. I've vardumped both the $product passed to the 
BasketControllers removeProduct()-action and the (in this case single) 
Product in $basket->products - I couldn't find any difference...

What am i doing wrong? Maybe it's just too late, but maybe there is a 
deeper misunderstand of anything...

Good night, Jan

---

class Basket extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity{

	/**
	 * products
	 *
	 * @var 
\TYPO3\CMS\Extbase\Persistence\ObjectStorage<\XX\Ext\Domain\Model\Product>
	 */
	protected $products;

	/**
	 * __construct
	 *
	 * @return Basket
	 */
	public function __construct() {
		//Do not remove the next line: It would break the functionality
		$this->initStorageObjects();
	}

	/**
	 * Initializes all ObjectStorage properties.
	 *
	 * @return void
	 */
	protected function initStorageObjects() {
		/**
		 * Do not modify this method!
		 * It will be rewritten on each save in the extension builder
		 * You may modify the constructor of this class instead
		 */
		$this->products = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();

	/**
	 * Adds a Product
	 *
	 * @param \XX\Ext\Domain\Model\Product $product
	 * @return void
	 */
	public function addProduct(\XX\Ext\Domain\Model\Product $product) {
		$this->products->attach($product);
	}

	/**
	 * Removes a Product
	 *
	 * @param \XX\Ext\Domain\Model\Product $product The Product to be 
removed
	 * @return void
	 */
	public function removeProduct(\XX\Ext\Domain\Model\Product $product) {
		$this->products->detach($product);
	}

}




More information about the TYPO3-project-typo3v4mvc mailing list