2017-08-17 38 views
-2

我有错字7.6.18。我需要将现有的项目添加到对象存储。我看到它不添加该项目。TYPO3对象存储添加现有项目

$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); 
} 

表中的TCA tx_feusersplus_domain_model_usersmile

<?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

我添加了用户模型。希望对你有帮助) – Mikael

+0

试图添加项目时是否没有错误消息? –

回答

0

您需要通过初始化每一个对象存储在你的模型:

public function __construct() 
{ 
    $this->smile = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); 
} 
+0

对不起,我清除所有缓存并尝试,但它仍然不添加相同的对象。 TCA可能会出错吗? – Mikael

+0

然后向我们展示TCA。 :) –

+0

我加了TCA)当我通过objectStorage添加项目到这个表格时,它没有设置crdate,为什么? – Mikael