[英]TYPO3 foreign_table: How to specify a specific column to a select drop down menu?
我想在TYPO3后端中添加记录。 为此,我做了一个扩展,其中包含4个不同的类。 在通过后端将一个特定类别的记录添加到文件夹时,我希望有一个选择项可以让我从另一个类别的列的项目中进行选择。 我知道我必须为此代码使用foreign_table
:
'kundeuid' => array(
'exclude' => 1,
'label' => 'LLL:EXT:icingaconfgen/Resources/Private/Language/locallang_db.xlf:tx_icingaconfgen_domain_model_appliance.kundeuid',
'config' => array(
'type' => 'select',
'renderType' => 'selectSingle',
'foreign_table' => 'tx_icingaconfgen_domain_model_kunde',
'foreign_table_where' => 'ORDER BY tx_icingaconfgen_domain_model_kunde.kundeuid asc',
'items' => array(
array('-- Select Kunde --', 0),
),
'size' => 1,
'maxitems' => 1
),
),
但是问题是我不能指定选择只包括确定列的属性。 相反,选择下拉菜单似乎使用了第一列的属性。 如何指定“ kundeuid”属性的列?
编辑:我忘了提及,该代码在TCA文件夹中的特定PHP文件中使用。
如果实现提供选择框内容的PHP方法,则可以用所需的任何内容填充选择。 为此,您必须使用itemsProcFunc
。
可能看起来像这样:
'kundeuid' => [
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'itemsProcFunc' => 'Vendor\Ext\ItemsProcFunc\KundeUid->fetchItems',
],
]
然后,在您的方法中,您可以用kunde表中的值填充items
数组(自己查看数据库):
/**
* Add two items to existing ones
*
* @param $params
*/
public function fetchItems(&$params)
{
$params['items'][] = ['customer01 (label)', 'customer01'];
$params['items'][] = ['customer02 (label)', 'customer02'];
}
请注意, $params
是通过引用传递的,该方法不需要返回任何内容。 同样,您在TCA配置中写入items
也将存在。 无论您选择什么,该选项的值都将存储在您的数据库字段中。
如果在TCA conf中使用'foreign_table'
,则将创建与外部表的关系,这总是意味着您将所选记录的uid存储在字段中(除非您正在使用MM表)。
在TYPO3中,每个记录都有一个在数据库中auto_increment
上的uid
,因此在每个表中都是唯一的。 以下TCA配置
'kundeuid' => [
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'foreign_table' => 'tx_icingaconfgen_domain_model_kunde',
],
]
将允许您在选择框中选择您的kunde
记录,并将其uid
存储在字段kundeuid
。 因此,如果让属性映射器在PHP代码中解决此依赖性(或者,如果使用存储库和域模型,则让extbase为您解决),您将得到如下所示的结果:
$appliance = $this->applianceRepository->findBySomething('something');
$kunde = $appliance->getKundeuid();
$kundeuid = $kunde->getKundeuid();
因此,我建议您重命名该字段,将TCA配置用于诸如client
东西,以使PHP代码变得不太混乱。
$appliance = $this->applianceRepository->findBySomething('something');
$client = $appliance->getClient();
$kundeuid = $client->getKundeuid();
在TCA的Kunde
记录的ctrl
部分中,将属性label
设置为Kunde
的名称表字段时,您也应该在Appliance
看到它。 也许其他属性label_
*对您有用。 链接到ctrl
文档: TCA参考
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.