2016-12-05 78 views
0

我做了一个类Appointmentexpertises属性和另一个subExpertises同类型的extbase扩展。
这是他们看起来像在Appointment类(subExpertises是相同的):调用未定义的方法getPosition() - 为什么和修复

/** 
* 
* @param \Domain\Model\Appointment $appointment 
* @return void 
*/ 
public function bookAction(\Domain\Model\Appointment $appointment) { 

    //empty all expertises of appointment - then fill them with the selected from lawyer 
    $appointment->setExpertises(new \TYPO3\CMS\Extbase\Persistence\ObjectStorage()); 
    $appointment->setSubExpertises(new \TYPO3\CMS\Extbase\Persistence\ObjectStorage()); 

    //add all checked expertises of lawyer to appointment 
    foreach ($appointment->getLawyer()->getExpertises() as $expertise) { 
     if ($expertise->getChecked()) { 
      $appointment->addExpertise($expertise); 
     } 
     foreach ($expertise->getSubExpertises() as $subExpertise) { 
      if ($subExpertise->getChecked()) { 
       $appointment->addSubExpertise($subExpertise); 
      } 
     } 
    } 
    $this->appointmentRepository->update($appointment); 
} 

/** 
    * expertises 
    * 
    * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<...\Domain\Model\Expertise> 
    */ 
    protected $expertises = NULL; 

    /** 
    * Adds an expertise 
    * 
    * @param ...\Domain\Model\Expertise $expertise 
    * @return void 
    */ 
    public function addExpertise(...\Domain\Model\Expertise $expertise) { 
     $this->expertises->attach($expertise); 
    } 

我流体的形式编辑后任命执行在我的控制器此代码时得到一个错误

这是错误:

Fatal error: Call to undefined method \Domain\Model\Expertise::getPosition() in /var/www/typo3_src/typo3_src-6.2.25/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php on line 453

现在看来,TYPO3认为ExpertiseObjectStorage型的,因为它试图调用getPosition(),但我不知道为什么这是否和我应该为了成功地挽救我Appointment对象与新Expertises改变

我试着调试约会对象,但我找不到问题 - 对我来说似乎没关系,它只是表明expertisessubExpertises已被修改。

+0

...你有不同的专门知识拼写,singluar属性,复数的方法。 – j4k3

+0

我再次检查了我的文本,但它很好 - 道具是objectStorage所以复数'expertises'和'subExpertises'类名是'Expertise'和'addExpertise'只添加一个,所以它应该是单数 –

回答

2

Extbase中的Getter方法并不神奇,您必须明确定义它们。

如果您正在处理n:n关系,则还需要在模型中将属性初始化为ObjectStorage并在TCA中对其进行配置。

/** 
* Initialize all ObjectStorage properties. 
* 
* @return void 
*/ 
protected function initStorageObjects() { 
    $this->yourProperty = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); 
} 
+0

谢谢,你有我在正确的轨道上 - 注意到'subExpertise'没有初始化为对象存储之后 - 我追溯了原因:这是因为我将扩展构建器中的关系设置为'1:n'而不是'm:n' –

相关问题