Burner
Burner

Reputation: 1071

TYPO3 Extbase fe_user UID in own model

I create a extbase Plugin in TYPO3 6.2. In one table i have a field "fuid" where i want to store the fe_users uid, to know which user can edit this record.

I set the "fuid" in createAction:

$newLocation->setFuID((int) $GLOBALS['TSFE']->fe_user->user['uid']);

This work. In the Database is the right UID.

But in the editAction:

$location->getFuID()
returns null

Why?

TCA:

fu_i_d' => array(
            'exclude' => 1,
            'label' => 'LLL:EXT:pitss24/Resources/Private/Language/locallang_db.xlf:tx_pitss24_domain_model_location.fu_i_d',
            'config' => array(
                'type' => 'select',
                'items' => array (
                        array('',0),
                ),
                'foreign_table' => 'fe_users',
                'foreign_class' => '\TYPO3\CMS\Extbase\Domain\Model\FrontendUser',
                'minitems' => 0,
                'maxitems' => 1,
                'size' => 10,
                'appearance' => array(
                    'collapseAll' => 0,
                    'levelLinksPosition' => 'top',
                    'showSynchronizationLink' => 1,
                    'showPossibleLocalizationRecords' => 1,
                    'showAllLocalizationLink' => 1
                ),
            ),
        ),

In the Backend / TYPO3 is all OK!

Upvotes: 1

Views: 5337

Answers (3)

Vishal Tanna
Vishal Tanna

Reputation: 1305

In Model File.

/**
 * feuseruid
 *
 * @var \TYPO3\CMS\Extbase\Domain\Model\FrontendUser
 */
protected $feuseruid;

// GET and SET Methods

/**
 * Returns the feuseruid
 *
 * @return \TYPO3\CMS\Extbase\Domain\Model\FrontendUser feuseruid
 */
public function getFeuseruid() {
     return $this->feuseruid;
}

/*
 * Sets the feuseruid
 *
 * @param string $feuseruid
 * @return \TYPO3\CMS\Extbase\Domain\Model\FrontendUser feuseruid
 */
public function setFeuseruid(\TYPO3\CMS\Extbase\Domain\Model\FrontendUser $feuseruid) {
     $this->feuseruid = $feuseruid;
}

In TCA File

'feuseruid' => array(
    'exclude' => 1,
    'label' => 'Feuser Id',
    'config' => array(
        'type' => 'inline',
        'foreign_table' => 'fe_users',
        'minitems' => 0,
        'maxitems' => 1,
        'appearance' => array(
            'collapseAll' => 0,
            'levelLinksPosition' => 'top',
            'showSynchronizationLink' => 1,
            'showPossibleLocalizationRecords' => 1,
            'showAllLocalizationLink' => 1
        ),
    ),
),

In Sql.php

feuseruid int(11) unsigned DEFAULT '0' NOT NULL,

In Controller

/**
 * User Repository
 *
 * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
 * @inject
 */
protected $userRepository;

$userObject = $this->userRepository->findByUid($GLOBALS['TSFE']->fe_user->user['uid']);
$orders->setFeuseruid($userObject);
$this->yourRepository->add($orders);

Upvotes: 2

Burner
Burner

Reputation: 1071

i found the Error! The extensionBuilder writes wrong Data in the Model:

the right values are:

Model:

/*
 *
 * @var TYPO3\CMS\Extbase\Domain\Model\FrontendUser
 */
protected $fuID = NULL;

...
...
...

/**
 * Returns the fuID
 *
 * @return TYPO3\CMS\Extbase\Domain\Model\FrontendUser fuID
 */
public function getFuID() {
    return $this->fuID;
}

/*
 * Sets the fuID
 *
 * @param string $fuID
 * @return TYPO3\CMS\Extbase\Domain\Model\FrontendUser fuID
 */
public function setFuID(TYPO3\CMS\Extbase\Domain\Model\FrontendUser $fuID) {
    $this->fuID = $fuID;
}

Controller:

/**
     * User Repository
     *
     * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
     * @inject
     */
    protected $userRepository;

    /**
     * Den aktuell angemeldeten User auslesen
     *
     * @return \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
     */
    public function getCurrentUser() {
        if ($this->currentUser == NULL && $GLOBALS['TSFE']->fe_user->user['uid'] > 0) {
            $this->currentUser = $this->userRepository->findByUid($GLOBALS['TSFE']->fe_user->user['uid']);
        }

        return $this->currentUser;  
    }

Upvotes: 1

RoyalKnight
RoyalKnight

Reputation: 139

Hard to say without the appropriate view of your model. It's very likely, that you have a mismatch between your model and your TCA: On the one hand you are using an integer (setFuID()), on the other hand you have an object (foreign_table/foreign_class). Maybe it's working after you have adjusted this to be the same.

Upvotes: 0

Related Questions