我的一个TYPO3扩展类使用属性(清单)作为对象存储。
class Kaufmnnisch extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
public function __construct(){
$this->checklist = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}
/**
* checklist
*
* @var Tx_Extbase_Persistence_ObjectStorage
* @lazy
*/
protected $checklist;
/**
* Returns the checklist
*
* @return Tx_Extbase_Persistence_ObjectStorage $checklist
*/
public function getChecklist()
{
return $this->checklist;
}
/**
* Sets the checklist
*
* @param Tx_Extbase_Persistence_ObjectStorage $checklist
* @return void
*/
public function setChecklist($checklist)
{
$this->checklist = $checklist;
}
/**
* Returns the boolean state of checklist
*
* @return bool
*/
public function isChecklist()
{
return $this->checklist;
}
对于那个对象存储,我希望能够添加“Checkobject”类的对象,它只有两个属性:'name'和'checked'... 在类的控制器中,我在createAction中有以下代码:
$Kundenauftragliegtvor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('...\Kundentermine\Domain\Model\Checkobject');
$Kundenauftragliegtvor->setName('Kundenauftrag liegt vor');
$Kaufmnnisch->getChecklist()->attach($Kundenauftragliegtvor);
所以基本上在创建该类的对象时,我想最初创建对象$ Kundenauftragliegtvor(当然后来我想添加该类的其他对象,但那是另一个故事)...但是:当创建一个对象时Kaufmnnisch类我收到以下错误:
Incorrect integer value: '' for column 'checklist' at row 1
似乎将对象附加到objectstorage'checklist'似乎在我的MySQL数据库中创建了错误。我怀疑我的TCA(特别是对象存储的部分)不正确:
'checklist' => [
'exclude' => true,
'label' => 'LLL:EXT:kundentermine/Resources/Private/Language/locallang_db.xlf:tx_kundentermine_domain_model_kaufmnnisch.checklist',
'config' => [
'type' => 'passthrough',
'items' => [
'1' => [
'0' => 'LLL:EXT:lang/locallang_core.xlf:labels.enabled'
]
],
'default' => 0,
]
],
编辑:在我的ext_tables.sql文件中,'checklist'的数据类型为:
checklist smallint(5) unsigned DEFAULT '0' NOT NULL,
我猜错误与此有关...但是我应该为对象存储指定什么数据类型?
答案 0 :(得分:1)
如果您有Checkobject,则应使用CheckobjectRepository并首先添加Checkobject。
尝试:
$Kundenauftragliegtvor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('...\Kundentermine\Domain\Model\Checkobject');
$checkobjectRepository = $this-objectManager->get('...\Kundentermine\Domain\Repository\CheckobjectRepository');
$checkobjectRepository->add($Kundenauftragliegtvor);
$Kundenauftragliegtvor->setName('Kundenauftrag liegt vor');
$Kaufmnnisch->getChecklist()->attach($Kundenauftragliegtvor);
注意:您也可以在控制器中注入存储库。
**
* checkobjectRepository
*
* @var ...\Kundentermine\Domain\Repository\CheckobjectRepository
*/
$protected $checkobjectRepository = null;
public function injectCheckobjectRepository(...\Kundentermine\Domain\Repository\CheckobjectRepository $checkobjectRepository) {
$this->checkobjectRepository = $checkobjectRepository;
}
如果您执行此更改,请不要忘记清除所有缓存,包括Optcode缓存。
您应该正确配置TCA:
'checklist' => [
'exclude' => true,
'label' => 'LLL:EXT:kundentermine/Resources/Private/Language/locallang_db.xlf:tx_kundentermine_domain_model_kaufmnnisch.checklist',
'config' => array(
'type' => 'select',
'foreign_table' => 'tx_kundentermine_domain_model_checkobject',
'foreign_table_where' => ' AND tx_kundentermine_domain_model_checkobject.sys_language_uid IN (-1,0) ORDER BY tx_kundentermine_domain_model_checkobject.title',
],
答案 1 :(得分:1)