2016-12-05 77 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' –

相關問題