问题描述
我想在更新对象时清空"对象存储空间:
I want to "empty" an ObjectStorage when updating a Object:
它是带有Extbase扩展的TYPO3 4.6,可让您在前端显示/添加/编辑/删除数据集.乍看之下,一切看起来都不错.
It's TYPO3 4.6 with a Extbase Extension which allows you to show/add/edit/delete datasets in the frontend. At first sight everything looks good.
我有一个字段引用了另一张表:
I have one field referencing another table:
TCA:
'partner' => array(
'exclude' => 0,
'label' => 'LLL:EXT:toco3_marketingdb/Resources/Private/Language/locallang_db.xlf:tx_toco3marketingdb_domain_model_firma.partner',
'config' => array(
'type' => 'select',
'size' => 5,
'foreign_table' => 'tx_toco3marketingdb_domain_model_partner',
'foreign_table_where' => 'ORDER BY tx_toco3marketingdb_domain_model_partner.partnerpkey',
'minitems' => 0,
'maxitems' => 20,
),
),
型号:
/**
* Partner
*
* @var Tx_Extbase_Persistence_ObjectStorage<Tx_Toco3Marketingdb_Domain_Model_Partner>
* @lazy
*/
protected $partner;
/**
* Sets the partner
*
* @param Tx_Extbase_Persistence_ObjectStorage<Tx_Toco3Marketingdb_Domain_Model_Partner> $partner
* @return void
*/
public function setPartner(Tx_Extbase_Persistence_ObjectStorage $partner) {
$this->partner = $partner;
}
控制器:
$partner = new Tx_Extbase_Persistence_ObjectStorage();
if (count($partnerarr) > 0){
foreach($partnerarr as $p){
$partner->attach( $this->partnerRepository->findByUid($p));
}
}
$organisation = $this->organisationRepository->findByUid($uid)
$organisation->setPartner($partner);
只要ObjectStorage中有一个Object,它就可以工作.所以我可以添加/删除/更改关系.但是,当$ partnerarr为空且没有对象被附加时,将分配一个空的Tx_Extbase_Persistence_ObjectStorage,旧值不会被删除".我也尝试分配null或",但是由于需要ObjectStorage而发生错误.如果我分配空的ObjectStorage我不会收到错误,但是旧值仍然保持:(
This is working as long there is an Object in the ObjectStorage. So I can add/delete/change relations. But when $partnerarr is empty an no objects get attached an empty Tx_Extbase_Persistence_ObjectStorage is assigned, the old values do not get "deleted". I also tried to assign null or "" but the an error occures because an ObjectStorage is needed. If I assign the empty ObjectStorage I don't get an error, but the old values still maintain :(
有什么主意吗?
谢谢
基督徒
推荐答案
调用detach
或removeAll
方法以删除存储的某些或所有对象.
Call the detach
or removeAll
methods to remove certain or all objects of the storage.
/** @var \Tx_Extbase_Persistence_ObjectStorage $organisationPartners */
$organisationPartners = $organisation->getPartner();
foreach ($organisationPartners as $partner) {
$organisationPartners->detach($partner);
}
这篇关于TYPO3 Extbase如何清空ObjectStorage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!