如果启用了 realURL,TYPO3 流体形式不起作用

TYPO3 fluid form not working if realURL is enabled

我创建了一个包含列表视图和详细视图的汽车扩展。详细视图还包含一个联系表。这个扩展在禁用 realURL 的情况下工作正常,但是对于 SEO 友好的 url,我已经启用并配置了 realURL 所以我的 url 有以下行为:

列表视图

domain.de/index.php?id=3 -> domain.de/cars/

详情查看

domain.de/index.php?id=38 -> domain.de/cars/details/

详情查看+获取参数car

domain.de/index.php?id=38&car=200 -> domain.de/cars/details/{brand-model}/

所以 URL 重写工作正常,我的扩展锚点从列表视图到详细视图也按预期工作,但我在详细视图上的联系表单不再工作。

我的表单的流体标记

<f:form action="send" method="post" name="request" section="form" object="{request}">
    <fieldset>
        <label>Salutation<span class="required">*</span>
            <f:render partial="FormErrors" arguments="{field: 'request.salutation'}" />
        </label>
        <f:form.hidden property="salutation" />
        <label>
            <f:form.radio property="salutation" value="female" />Frau
        </label>
        <label>
            <f:form.radio property="salutation" value="male" />Herr
        </label>
    </fieldset>
    <fieldset>
        <label for="name">Name<span class="required">*</span>
             <f:render partial="FormErrors" arguments="{field: 'request.name'}" />
        </label>
        <f:form.textfield property="name" />
    </fieldset>

    ....

    <fieldset>
         <f:form.submit class="button" name="send" value="Send" />
    </fieldset>
</f:form>

如果我使用开发人员工具检查此表单,我会得到以下标记:

启用真实URL

<form method="post" name="request" action="cars/details/?tx_foxcars_p1%5Baction%5D=send&amp;cHash=f654ce4fb67a5b5c636508675c18d4c3#form">

禁用真实URL

<form method="post" name="request" action="index.php?id=38&tx_foxcars_p1%5Baction%5D=send&cHash=f654ce4fb67a5b5c636508675c18d4c3#form">

我认为没问题,但如果我提交启用了真实URL 的表单,我会得到我的 404 页面的内容。禁用 realURL 后,它按预期工作。

我的 sendAction 如下所示:

public function sendAction(\Fox\FoxCars\Domain\Model\Request $request)
{
    $fromEmail = $request->getEmail();
    $fromName = $request->getName();
    $toEmail = $this->settings['senderEmail'];
    $toName = $this->settings['senderName'];
    $subject = $this->settings['subject'];
    $body = $request->getBody();

    $mail = GeneralUtility::makeInstance('TYPO3\CMS\Core\Mail\MailMessage');
    $mail->setFrom(array($fromEmail => $fromName));
    $mail->setTo(array($toEmail => $toName));
    $mail->setSubject($subject);
    $mail->setBody($body, 'text/html');
    $mail->send();

    if ($mail->isSent()) {
        $this->redirect('send', null, null, null, $this->settings['confirmPageId']);
    }
}

但是好像启用了realURL这个动作就不会执行了。

我的真实URL配置如下:

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'] = array(
    '_DEFAULT' => array(
        'init' => array(
            'enableCHashCache' => true,
            'appendMissingSlash' => 'ifNotFile,redirect',
            'adminJumpToBackend' => true,
            'enableUrlDecodeCache' => true,
            'enableUrlEncodeCache' => true,
            'respectSimulateStaticURLs' => false,
            'emptyUrlReturnValue' => '/',
        ),
        'pagePath' => array(
            'type' => 'user',
            'userFunc' => 'EXT:realurl/class.tx_realurl_advanced.php:&tx_realurl_advanced->main',
            'spaceCharacter' => '-',
            'languageGetVar' => 'L',
            'rootpage_id' => '1',
        ),
        'fileName' => array(
            'defaultToHTMLsuffixOnPrev' => 0,
            'acceptHTMLsuffix' => 1,
            'index' => array(
                'print' => array(
                    'keyValues' => array(
                        'type' => 98,
                    ),
                ),
            ),
        ),
        'fixedPostVars' => array(
            'carsDetailConfiguration' => array(
                array(
                    'GETvar' => 'car',
                    'lookUpTable' => array(
                        'table' => 'tx_foxcars_domain_model_car',
                        'id_field' => 'uid',
                        'alias_field' => "CONCAT(brand, '-', model)",
                        'addWhereClause' => ' AND NOT deleted',
                        'useUniqueCache' => 1,
                        'useUniqueCache_conf' => array(
                            'strtolower' => 1,
                            'spaceCharacter' => '-'
                        ),
                        'languageGetVar' => 'L',
                        'languageExceptionUids' => '',
                        'languageField' => 'sys_language_uid',
                        'transOrigPointerField' => 'l10n_parent'
                    )
                )
            ),
            '38' => 'carsDetailConfiguration',
            'newsDetailConfiguration' => array(
                array(
                    'GETvar' => 'tx_news_pi1[news]',
                    'lookUpTable' => array(
                        'table' => 'tx_news_domain_model_news',
                        'id_field' => 'uid',
                        'alias_field' => 'title',
                        'useUniqueCache' => 1,
                        'useUniqueCache_conf' => array(
                            'strtolower' => 1,
                            'spaceCharacter' => '-',
                        ),
                    ),
                ),
            ),
            '35' => 'newsDetailConfiguration',
        ),
        'postVarSets' => array(
            '_DEFAULT' => array(
                'news' => array(
                    0 => array(
                        'GETvar' => 'tx_news_pi1[news]',
                        'lookUpTable' => array(
                            'table' => 'tx_news_domain_model_news',
                            'id_field' => 'uid',
                            'alias_field' => 'title',
                            'useUniqueCache' => 1,
                            'useUniqueCache_conf' => array(
                                'strtolower' => 1,
                                'spaceCharacter' => '-',
                            ),
                        ),
                    ),
                ),
                'cars' => array(
                    0 => array(
                        'GETvar' => 'car',
                        'lookUpTable' => array(
                            'table' => 'tx_foxcars_domain_model_car',
                            'id_field' => 'uid',
                            'alias_field' => "CONCAT(brand, '-', model)",
                            'useUniqueCache' => 1,
                            'useUniqueCache_conf' => array(
                                'strtolower' => 1,
                                'spaceCharacter' => '-',
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
);

也许 realURL 配置有误?那么realURL期待get参数"car",却只获取send动作?所以汽车丢失且未找到 -> 404?

希望你能帮助我:)

忘记补充了

additionalParams="{car: car}"

到我的表格。所以我改变了

<f:form action="send" method="post" name="request" section="form" object="{request}">

<f:form action="send" additionalParams="{car: car}" method="post" name="request" section="form" object="{request}">

现在可以使用了:)。