我有拼写错误7.6.18。我需要将现有项添加到对象存储。我看到它没有添加项目。
$editUser = $this->userRepository->findByUid($userUid);
$newSmile = $this->serviceRepository->findByUid($smileUid);
if ($editUser && $newSmile) {
$smileUid = $newSmile->getUid();
$editUser->addSmile($newSmile);
$this->userRepository->update($editUser);
$persistenceManager->persistAll();
}
请帮帮我。 模型用户,所有触摸微笑对象存储。我添加了我的用户模型。对不起我必须写点东西。我必须写更多。
/**
* smiles
*
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Fhk\Feusersplus\Domain\Model\Service>
*/
protected $smile = '';
/**
* Returns the smiles
*
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Fhk\Feusersplus\Domain\Model\Service> $smile
*/
public function getSmile()
{
return $this->smile;
}
/**
* Sets the smile
*
* @return void
*/
public function setSmile($smile)
{
$this->smile = $smile;
}
/**
* Adds a smile to the smile
*
* @param \Fhk\Feusersplus\Domain\Model\Service $smile
* @return void
* @api
*/
public function addSmile(\Fhk\Feusersplus\Domain\Model\Service $smile)
{
$this->smile->attach($smile);
}
/**
* Removes a smile from the smile
*
* @param \Fhk\Feusersplus\Domain\Model\Service $smile
* @return void
* @api
*/
public function removeSmile(\Fhk\Feusersplus\Domain\Model\Service $smile)
{
$this->smile->detach($smile);
}
表tx_feusersplus_domain_model_usersmile的TCA
<?php
return [
'ctrl' => [
'title' => 'LLL:EXT:feusersplus/Resources/Private/Language/locallang_db.xlf:userSmile',
'label' => 'uid_local',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
'sortby' => 'sorting',
'hideTable' => true,
'languageField' => 'sys_language_uid',
'transOrigPointerField' => 'l10n_parent',
'transOrigDiffSourceField' => 'l10n_diffsource',
'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('feusersplus') . 'Resources/Public/Icons/tx_feusersplus_domain_model_hut.gif'
],
'interface' => [
'showRecordFieldList' => 'uid_local,uid_foreign'
],
'types' => [
'1' => ['showitem' => 'sys_language_uid;;;;1-1-1, l10n_parent, l10n_diffsource;;1, uid_local, uid_foreign,--div--;LLL:EXT:cms/locallang_ttc.xlf:tabs.access'],
],
'palettes' => [
'1' => ['showitem' => ''],
],
'columns' => [
'sys_language_uid' => [
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.language',
'config' => [
'type' => 'select',
'foreign_table' => 'sys_language',
'foreign_table_where' => 'ORDER BY sys_language.title',
'items' => [
['LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages', -1],
['LLL:EXT:lang/locallang_general.xlf:LGL.default_value', 0]
],
],
],
'l10n_parent' => [
'displayCond' => 'FIELD:sys_language_uid:>:0',
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.l18n_parent',
'config' => [
'type' => 'select',
'items' => [
['', 0],
],
'foreign_table' => 'tx_fefiles_domain_model_photo',
'foreign_table_where' => 'AND tx_fefiles_domain_model_photo.pid=###CURRENT_PID### AND tx_fefiles_domain_model_photo.sys_language_uid IN (-1,0)',
],
],
'l10n_diffsource' => [
'config' => [
'type' => 'passthrough',
],
],
't3ver_label' => [
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.versionLabel',
'config' => [
'type' => 'input',
'size' => 30,
'max' => 255,
]
],
'uid_local' => [
'exclude' => 1,
'label' => 'LLL:EXT:feusersplus/Resources/Private/Language/locallang_db.xlf:user',
'config' => [
'type' => 'select',
'foreign_table' => 'fe_users',
'minitems' => 1,
'maxitems' => 1,
]
],
'uid_foreign' => [
'exclude' => 1,
'label' => 'LLL:EXT:feusersplus/Resources/Private/Language/locallang_db.xlf:smile',
'config' => [
'type' => 'select',
'foreign_table' => 'tx_feusersplus_domain_model_service',
// 'foreign_field' => 'uid',
// 'foreign_table_where' => 'AND tx_feusersplus_domain_model_service.sys_language_uid=###REC_FIELD_sys_language_uid### ',
'foreign_match_fields' => [
'type' => 1
],
'minitems' => 1,
'maxitems' => 1,
]
],
'crdate' => array(
'exclude' => 0,
'label' => 'LLL:EXT:feusersplus/Resources/Private/Language/locallang_db.xlf:crdate',
'config' => array(
'type' => 'input',
'size' => 10,
'max' => 20,
'eval' => 'date',
'checkbox' => '0',
'default' => ''
)
),
],
];
顺便说一句,我将此表用于MM关系。
答案 0 :(得分:0)
您需要通过以下方式初始化模型中的每个对象存储:
public function __construct()
{
$this->smile = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}