TYPO3 Extbase fe_user UID in own model

自闭症网瘾萝莉.ら 提交于 2019-12-06 13:35:07

问题


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!


回答1:


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);



回答2:


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;  
    }



回答3:


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.



来源:https://stackoverflow.com/questions/26076481/typo3-extbase-fe-user-uid-in-own-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!