2014-04-07 36 views
1

im试图在我的ImportCommandController.php中创建和保存一个值对象,但只保存实体。在CommandController中创建并保存一个值对象

让我告诉一些代码:

// Create Entity "Fewo" 
$fewo = new Fewo(); 
$fewo->setTitle('MyFewo'); 
... 

// Create Value Object "Period" 
$period = new Period(); 
$period->setTitle('MyTestTitle'); 
... 

$fewo->addPeriod($period); 

$this->fewoRepository->add($fewo); 
$this->persistenceManager->persistAll(); 

现在Fewo酒店是在数据库中,但周期表仍然是空的。我找不到我的错......

UPDATE:

这是时代型号:

<?php 

namespace TYPO3\Fewo\Domain\Model; 

class Period extends \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject { 

/** 
* Name der Saison 
* 
* @var \string 
*/ 
protected $name; 

/** 
* Von 
* 
* @var \DateTime 
*/ 
protected $begin; 

/** 
* Bis 
* 
* @var \DateTime 
*/ 
protected $end; 

/** 
* rentalcharges 
* 
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\Fewo\Domain\Model\Rentalcharge> 
*/ 
protected $rentalcharges; 

/** 
* __construct 
* 
* @return Period 
*/ 
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->rentalcharges = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); 
} 

/** 
* Returns the name 
* 
* @return \string $name 
*/ 
public function getName() { 
    return $this->name; 
} 

/** 
* Sets the name 
* 
* @param \string $name 
* @return void 
*/ 
public function setName($name) { 
    $this->name = $name; 
} 

/** 
* Returns the begin 
* 
* @return \DateTime $begin 
*/ 
public function getBegin() { 
    return $this->begin; 
} 

/** 
* Sets the begin 
* 
* @param \DateTime $begin 
* @return void 
*/ 
public function setBegin($begin) { 
    $this->begin = $begin; 
} 

/** 
* Returns the end 
* 
* @return \DateTime $end 
*/ 
public function getEnd() { 
    return $this->end; 
} 

/** 
* Sets the end 
* 
* @param \DateTime $end 
* @return void 
*/ 
public function setEnd($end) { 
    $this->end = $end; 
} 

/** 
* Adds a Rentalcharge 
* 
* @param \TYPO3\Fewo\Domain\Model\Rentalcharge $rentalcharge 
* @return void 
*/ 
public function addRentalcharge(\TYPO3\Fewo\Domain\Model\Rentalcharge $rentalcharge) { 
    $this->rentalcharges->attach($rentalcharge); 
} 

/** 
* Removes a Rentalcharge 
* 
* @param \TYPO3\Fewo\Domain\Model\Rentalcharge $rentalchargeToRemove The Rentalcharge to be removed 
* @return void 
*/ 
public function removeRentalcharge(\TYPO3\Fewo\Domain\Model\Rentalcharge $rentalchargeToRemove) { 
    $this->rentalcharges->detach($rentalchargeToRemove); 
} 

/** 
* Returns the rentalcharges 
* 
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\Fewo\Domain\Model\Rentalcharge> $rentalcharges 
*/ 
public function getRentalcharges() { 
    return $this->rentalcharges; 
} 

/** 
* Sets the rentalcharges 
* 
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\Fewo\Domain\Model\Rentalcharge> $rentalcharges 
* @return void 
*/ 
public function setRentalcharges(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $rentalcharges) { 
    $this->rentalcharges = $rentalcharges; 
} 

}

UPDATE2:

尝试:

class Period extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {...} 

和:

$period = $this->objectManager->get('TYPO3\Fewo\Domain\Model\Period'); 

没有效果:(

+0

你应该使用对象管理器来获得一个新的对象实例。 $ this-> objectManager-> get($ objectName) 请发布您的Period类 – fazzyx

+0

没有人得到答案? :( – Milzer

+0

您是否已尝试通过objectManager创建/获取对象? 尝试从AbstractEntity而不是AbstractValueObject扩展Period类。我不确定ValueObject是否已完全实现。 – fazzyx

回答

0

是在正确类型的FEWO期? 它必须是这样的:

* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\Fewo\Domain\Model\Fewo> 
相关问题