【发布时间】:2017-04-20 11:10:18
【问题描述】:
我创建了一个 extbase 扩展,其类 Appointment 具有属性 expertises 和另一个相同类型的 subExpertises。
这是它们在Appointment 类中的样子(subExpertises 是一样的):
/**
* 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);
}
在以流畅的形式编辑约会后,在控制器中执行此代码时出现错误:
/**
*
* @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);
}
这是错误:
致命错误:调用 /var/www/typo3_src/typo3_src-6.2.25/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php 中的未定义方法 \Domain\Model\Expertise::getPosition()在第 453 行
现在看来 TYPO3 认为 Expertise 是 ObjectStorage 类型,因为它试图调用 getPosition() 但我不知道 为什么 它会这样做以及 我应该改变什么 为了使用新的Expertises 成功保存我的Appointment 对象。
我尝试调试约会对象,但找不到问题 - 对我来说似乎没问题,它只是表明 expertises 和 subExpertises 已被修改。
【问题讨论】:
-
...您有不同的专业知识拼写,属性中的单数,方法中的复数。
-
我再次检查了我的文本,但它很好 - 道具是 objectStorage 所以复数
expertises和subExpertises类名是Expertise和addExpertise只添加一个,所以它应该单数
标签: typo3 extbase typo3-6.2.x