简体   繁体   中英

TYPO3 relation to fe_users in custom extension

I am writing an extbase extension in TYPO3 7.6 to organize a team. The extension key is squad. Every team belongs to a trainer which has a record in the fe_users table. So in my team model I have a relation to the fe_users table. I started with the extension builder and afterwards adjusted my model following the instructions on these sites: https://www.typo3.net/forum/thematik/zeige/thema/126982/ and TYPO3 Extbase fe_user UID in own model In the backend the relation works fine, but in the frontend I don't get the trainer listed in the team view. What is missing?

My code is as following.

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

Okay, I found the answer. The setup above is correct. But as I set in ext_typoscript_setup.txt

recordType = Tx_Squad_FrontendUser

I could only use fe_users who were assigned to the recordType Tx_Squad_FrontendUser. After assigning the correct recordType to the fe_users everything worked fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM