【问题标题】:TYPO3 relation to fe_users in custom extensionTYPO3 与自定义扩展中的 fe_users 的关系
【发布时间】:2018-09-27 08:36:50
【问题描述】:

我正在 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;
    }
}

模板/团队/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>
...

【问题讨论】:

  • 能否也添加 Fluid 模板?
  • 我现在添加了流体模板。如果我调试团队,即使后端显示了培训师,我也会为培训师获得 NULL。

标签: foreign-keys typo3 extbase typo3-7.6.x


【解决方案1】:

好的,我找到了答案。上面的设置是正确的。但正如我在 ext_typoscript_setup.txt 中设置的

recordType = Tx_Squad_FrontendUser

我只能使用分配给 recordType Tx_Squad_FrontendUser 的 fe_users。 将正确的记录类型分配给 fe_users 后一切正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-14
    • 1970-01-01
    • 2023-01-04
    相关资源
    最近更新 更多