我正在TYPO3 7.6中编写一个extbase扩展来组织一个团队。分机密钥是小队。每个团队都属于一个培训师,该培训师在fe_users表中有一条记录。 因此,在我的团队模型中,我与fe_users表有关系。 我从扩展程序构建器开始,然后按照以下网站上的说明调整了模型:https://www.typo3.net/forum/thematik/zeige/thema/126982/和 TYPO3 Extbase fe_user UID in own model 在后端,这种关系很好,但是在前端,我没有在团队视图中列出培训者。 缺少什么?
我的代码如下。
ext_tables.sql:
CREATE TABLE tx_squad_domain_model_team (
...
trainer int(11) unsigned DEFAULT '0',
...
)
TCA.php:
'trainer' => [
'label' => 'Trainer',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'foreign_table' => 'fe_users',
'minitems' => 0,
'maxitems' => 1,
],
]
ext_typoscript_setup.txt
config.tx_extbase {
persistence {
classes {
TYPO3\CMS\Extbase\Domain\Model\FrontendUser {
subclasses {
Tx_Squad_FrontendUser = VENDOR\Squad\Domain\Model\FrontendUser
}
}
VENDOR\Squad\Domain\Model\FrontendUser {
mapping {
tableName = fe_users
recordType = Tx_Squad_FrontendUser
}
}
}
}
}
Model Team.php
class Team extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
/**
* trainer
*
* @var \TYPO3\CMS\Extbase\Domain\Model\FrontendUser
*/
protected $trainer;
/**
* Returns the trainer
*
* @return \TYPO3\CMS\Extbase\Domain\Model\FrontendUser $trainer
*/
public function getTrainer()
{
return $this->trainer;
}
/**
* Sets the trainer
*
* @param \TYPO3\CMS\Extbase\Domain\Model\FrontendUser $trainer
* @return void
*/
public function setTrainer(\TYPO3\CMS\Extbase\Domain\Model\FrontendUser $trainer)
{
$this->trainer = $trainer;
}
}
Templates / Team / List.html
...
<f:for each="{teams}" as="team">
<f:debug>{team}</f:debug>
<tr>
<td>{team.trainer}</td>
<td><f:link.action action="show" arguments="{team: team}"> {team.name}</f:link.action></td>
<td><f:link.action action="show" arguments="{team: team}"> {team.ccemail}</f:link.action></td>
<td><f:link.action action="edit" arguments="{team: team}">Edit</f:link.action></td>
<td><f:link.action action="delete" arguments="{team: team}">Delete</f:link.action></td>
</tr>
</f:for>
...
答案 0 :(得分:0)
好的,我找到了答案。上面的设置正确。但是正如我在ext_typoscript_setup.txt中设置的
recordType = Tx_Squad_FrontendUser
我只能使用分配给recordType Tx_Squad_FrontendUser的fe_users。 将正确的recordType分配给fe_users后,一切正常。