Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
TYPO3对象存储为空_Typo3_Relation_Fluid_Extbase_Typo3 6.2.x - Fatal编程技术网

TYPO3对象存储为空

TYPO3对象存储为空,typo3,relation,fluid,extbase,typo3-6.2.x,Typo3,Relation,Fluid,Extbase,Typo3 6.2.x,我想从一个模特到另一个模特 /** * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface * @inject */ protected $objectManager; /** * action create * * @param \ReRe\Rere\Domain\Model\Modul $newModul * @return void */ public function createAction(\ReRe\Re

我想从一个模特到另一个模特

/**
 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
 * @inject
 */
protected $objectManager;



/**
 * action create
 *
 * @param \ReRe\Rere\Domain\Model\Modul $newModul
 * @return void
 */
public function createAction(\ReRe\Rere\Domain\Model\Modul $newModul) {
    $this->addFlashMessage('The object was created. Please be aware that this action is publicly accessible unless you implement an access check. See <a href="http://wiki.typo3.org/T3Doc/Extension_Builder/Using_the_Extension_Builder#1._Model_the_domain" target="_blank">Wiki</a>', '', \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR);
    $this->modulRepository->add($newModul);
    // Erzeugt ein Leeres Fach
    $fachHelper = new \ReRe\Rere\Domain\Model\Fach();


    $fach = $this->objectManager->create('\ReRe\Rere\Domain\Model\Fach');


    // Fach Werte setzen
    $fach->setFachname($this->request->getArgument('fachname'));
    $fach->setFachnr($this->request->getArgument('fachnummer'));
    $fach->setPruefer($this->request->getArgument('pruefer'));
    $fach->setNotenschema($this->request->getArgument('notenschema'));
    // Fach einem Modul zuordnen

    $fach->setModulnr($newModul->getModulnr());
    //$request = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance("\ReRe\Rere\Domain\Model\Fach");
    //\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($newModul);
    // Fach speichern
    $this->fachRepository->add($fach);

    $newModul->addFach($fach);
    $this->redirect('list');
}

和TCA Fach

<?php
if (!defined ('TYPO3_MODE')) {
    die ('Access denied.');
}

$GLOBALS['TCA']['tx_rere_domain_model_fach'] = array(
'ctrl' => $GLOBALS['TCA']['tx_rere_domain_model_fach']['ctrl'],
'interface' => array(
    'showRecordFieldList' => 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, fachnr, fachname, pruefer, notenschema, modulnr, matrikelnr',
),
'types' => array(
    '1' => array('showitem' => 'sys_language_uid;;;;1-1-1, l10n_parent, l10n_diffsource, hidden;;1, fachnr, fachname, pruefer, notenschema, modulnr, matrikelnr, --div--;LLL:EXT:cms/locallang_ttc.xlf:tabs.access, starttime, endtime'),
),
'palettes' => array(
    '1' => array('showitem' => ''),
),
'columns' => array(

    'sys_language_uid' => array(
        'exclude' => 1,
        'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.language',
        'config' => array(
            'type' => 'select',
            'foreign_table' => 'sys_language',
            'foreign_table_where' => 'ORDER BY sys_language.title',
            'items' => array(
                array('LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages', -1),
                array('LLL:EXT:lang/locallang_general.xlf:LGL.default_value', 0)
            ),
        ),
    ),
    'l10n_parent' => array(
        'displayCond' => 'FIELD:sys_language_uid:>:0',
        'exclude' => 1,
        'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.l18n_parent',
        'config' => array(
            'type' => 'select',
            'items' => array(
                array('', 0),
            ),
            'foreign_table' => 'tx_rere_domain_model_fach',
            'foreign_table_where' => 'AND tx_rere_domain_model_fach.pid=###CURRENT_PID### AND tx_rere_domain_model_fach.sys_language_uid IN (-1,0)',
        ),
    ),
    'l10n_diffsource' => array(
        'config' => array(
            'type' => 'passthrough',
        ),
    ),

    't3ver_label' => array(
        'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.versionLabel',
        'config' => array(
            'type' => 'input',
            'size' => 30,
            'max' => 255,
        )
    ),

    'hidden' => array(
        'exclude' => 1,
        'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.hidden',
        'config' => array(
            'type' => 'check',
        ),
    ),
    'starttime' => array(
        'exclude' => 1,
        'l10n_mode' => 'mergeIfNotBlank',
        'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.starttime',
        'config' => array(
            'type' => 'input',
            'size' => 13,
            'max' => 20,
            'eval' => 'datetime',
            'checkbox' => 0,
            'default' => 0,
            'range' => array(
                'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y'))
            ),
        ),
    ),
    'endtime' => array(
        'exclude' => 1,
        'l10n_mode' => 'mergeIfNotBlank',
        'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.endtime',
        'config' => array(
            'type' => 'input',
            'size' => 13,
            'max' => 20,
            'eval' => 'datetime',
            'checkbox' => 0,
            'default' => 0,
            'range' => array(
                'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y'))
            ),
        ),
    ),

    'fachnr' => array(
        'exclude' => 1,
        'label' => 'LLL:EXT:rere/Resources/Private/Language/locallang_db.xlf:tx_rere_domain_model_fach.fachnr',
        'config' => array(
            'type' => 'input',
            'size' => 30,
            'eval' => 'trim'
        ),
    ),
    'fachname' => array(
        'exclude' => 1,
        'label' => 'LLL:EXT:rere/Resources/Private/Language/locallang_db.xlf:tx_rere_domain_model_fach.fachname',
        'config' => array(
            'type' => 'input',
            'size' => 30,
            'eval' => 'trim,required'
        ),
    ),
    'pruefer' => array(
        'exclude' => 1,
        'label' => 'LLL:EXT:rere/Resources/Private/Language/locallang_db.xlf:tx_rere_domain_model_fach.pruefer',
        'config' => array(
            'type' => 'input',
            'size' => 30,
            'eval' => 'trim'
        ),
    ),
    'notenschema' => array(
        'exclude' => 1,
        'label' => 'LLL:EXT:rere/Resources/Private/Language/locallang_db.xlf:tx_rere_domain_model_fach.notenschema',
        'config' => array(
            'type' => 'input',
            'size' => 30,
            'eval' => 'trim,required'
        ),
    ),
    'modulnr' => array(
        'exclude' => 1,
        'label' => 'LLL:EXT:rere/Resources/Private/Language/locallang_db.xlf:tx_rere_domain_model_fach.modulnr',
        'config' => array(
            'type' => 'input',
            'size' => 30,
            'eval' => 'trim,required'
        ),
    ),
    'matrikelnr' => array(
        'exclude' => 1,
        'label' => 'LLL:EXT:rere/Resources/Private/Language/locallang_db.xlf:tx_rere_domain_model_fach.matrikelnr',
        'config' => array(
            'type' => 'select',
            'foreign_table' => 'tx_rere_domain_model_pruefling',
            'MM' => 'tx_rere_fach_pruefling_mm',
            'size' => 10,
            'autoSizeMax' => 30,
            'maxitems' => 9999,
            'multiple' => 0,
            'wizards' => array(
                '_PADDING' => 1,
                '_VERTICAL' => 1,
                'edit' => array(
                    'type' => 'popup',
                    'title' => 'Edit',
                    'script' => 'wizard_edit.php',
                    'icon' => 'edit2.gif',
                    'popup_onlyOpenIfSelected' => 1,
                    'JSopenParams' => 'height=350,width=580,status=0,menubar=0,scrollbars=1',
                    ),
                'add' => Array(
                    'type' => 'script',
                    'title' => 'Create new',
                    'icon' => 'add.gif',
                    'params' => array(
                        'table' => 'tx_rere_domain_model_pruefling',
                        'pid' => '###CURRENT_PID###',
                        'setValue' => 'prepend'
                        ),
                    'script' => 'wizard_add.php',
                ),
            ),
        ),
    ),

    'modul' => array(
        'config' => array(
            'type' => 'passthrough',
        ),
    ),
    'note' => array(
        'config' => array(
            'type' => 'passthrough',
        ),
    ),
),
);

请检查ObjectStorage是否与模型中的正确类相关。有时候extensionbuilder确实设置了ObjectStorage,但却弄乱了注释

检查ReRe\ReRe\Domain\Model\Modul类中“fach”的注释是否包含引用的类。应该是这样的:

<f:for each="{moduls}" as="modul">

{modul.modulname}

<f:for each="{modul.fach}" as="fach">
{fach.fachname} 
@var\TYPO3\CMS\Extbase\Persistence\ObjectStorage

如果假设您的外观与此类似,这是错误的,并导致FE中的ObjectStorage为空: @var\TYPO3\CMS\Extbase\Persistence\ObjectStorage


查看ObjectStorage包含的类是如何丢失的。

模型类看起来正常,所有注释似乎都正确

请发布Modul和Fach的TCA配置(两者的关系条目应该足够了)

快速提问,你能在后端看到两个对象之间的关系吗?如果能,你能从两侧看到吗? 如果可以在“模块”对象中看到相关的“Fach”对象,请转到BE并使用列表工具进行检查,反之亦然

可能TCA关系没有正确设置,您只能从一侧访问该关系

您从哪一方创建了关系(Modul->Fach或Fach->Modul)? 当然,这两种方式都应该有效

更新1

表“tx\u rere\u domain\u model\u fach”中的“modulnr”列是否包含正确的模块UID

->为了加快进程,你能给我发一个你分机的下载链接吗?然后我会把它安装在一个测试系统上,我们会很快发现问题所在

更新2

我发现你的分机出了什么问题。创建新的Modul和Fach后,类\ReRe\ReRe\Controller\ModulController将处理表单数据。第116行

$fach->setModulnr($newModul->getModulnr());
参考值应为模块的UID设置为模块编号。由于对外部表的引用配置为UID,因此需要在此处设置模块的UID。将该行更改为以下内容,它将正常工作:

$fach->setModulnr($newModul->getUid());
您必须在创建新Fach模块关系的每个控制器操作中更改此设置。所以这只是一个你需要做的例子

旁注

作为附加提示,您可能希望了解如何在Extbase中处理表单数据的最佳实践

像这样的电话

$fach->setFachnr($this->request->getArgument('fachnummer'));
会起作用,但在注射方面会带来痛苦,因为没有验证等

设置基本验证并使代码更具可读性的一种非常简单快捷的方法是在控制器操作中使用注释和参数。因此,与其自己获取参数,不如让框架为您工作:

/**
 * action create
 *
 * @param \ReRe\Rere\Domain\Model\Modul $newModul
 * @param string                        $fachname
 * @param int                           $fachnummer
 */
public function createAction(\ReRe\Rere\Domain\Model\Modul $newModul, $fachname, $fachnummer) {
...
如果要使参数成为可选参数,只需在方法调用中为其指定一个值:

public function createAction(\ReRe\Rere\Domain\Model\Modul $newModul, $fachname = "foo", $fachnummer="bar") {
...

正如我所说的,这只是一个小窍门,你可能想考虑一下:

谢谢你的回答。我的模型是这样的:
/***fach**@var\TYPO3\CMS\Extbase\Persistence\ObjectStorage*@cascade remove*/protected$fach=NULL看起来还可以吗?你还有别的想法吗?为什么我会有这个问题?是的,看起来不错。请发布整个类\ReRe\ReRe\Domain\Model\module可能对象存储或其他注释(例如getter注释)的初始化有问题。您好,谢谢您的帮助。我已经添加了Domain/Modul.php和两个TCA配置。在我的第一篇文章中创建的操作在modulecontroller.php中,整个操作是一个后端模块。在哪里可以检查后端中的关系?要检查关系,只需登录到后端,请转到左侧的“列表”工具,并从页面树中选择包含实体的存储系统文件夹。如果您不确定实体存储在哪里,只需检查数据库表,“pid”列将为您提供存储文件夹的UID。然后,只需在TYPO3后端的搜索字段中键入UID,就可以找到包含实体的文件夹。要检查关系,只需编辑一个模块对象,然后查看Fach对象是否存在,从另一端看是否相同。没有列表模块(或您是指web下的模块)您是否查看了tca配置?列表模块应该是“web”类别中的第三个模块。默认情况下,您有“页面、视图、列表、函数…”。我现在要看一下TCA我想我没有保存uid,我保存了整个对象。。这是链接,请告诉我你什么时候下载的
public function createAction(\ReRe\Rere\Domain\Model\Modul $newModul, $fachname = "foo", $fachnummer="bar") {
...