Typo3 独立视图表单

Typo3 Standalone View Form

我在 extbase 中遇到独立视图问题。

问题在于,当使用独立视图生成视图时,表单不正确。如果我使用默认生成器,表单如下所示:

<form role="form" name="user" id="validateEmailForm" action="index.php?id=2&amp;tx_registration_userregistration%5Buser%5D=&amp;tx_registration_userregistration%5Baction%5D=validateEmail&amp;tx_registration_userregistration%5Bcontroller%5D=User&amp;cHash=b608ba14aff3a034be5e58a0402b96c0" method="post">
    <div>
        <input name="tx_registration_userregistration[__referrer][@extension]" value="Registration" type="hidden">
        <input name="tx_registration_userregistration[__referrer][@vendor]" value="Whmcs" type="hidden">
        <input name="tx_registration_userregistration[__referrer][@controller]" value="User" type="hidden">
        <input name="tx_registration_userregistration[__referrer][@action]" value="test" type="hidden">
        <input name="tx_registration_userregistration[__referrer][arguments]" value="YToyOntzOjY6ImFjdGlvbiI7czo0OiJ0ZXN0IjtzOjEwOiJjb250cm9sbGVyIjtzOjQ6IlVzZXIiO30=0fea5b97636b178cebbb4da9ed487d5e77f205ae" type="hidden">
        <input name="tx_registration_userregistration[__trustedProperties]" value="a:1:{s:4:&quot;user&quot;;a:2:{s:12:&quot;eMailAddress&quot;;i:1;s:13:&quot;eMailVerified&quot;;i:1;}}bbc1e3377150a6976a7dbec4197d034951d29ef0" type="hidden">
    </div>

    <div class="form-group">
        <label>E-Mail Adresse</label>
        <input class="form-control" name="tx_registration_userregistration[user][eMailAddress]" type="text">
    </div>

    <div class="form-group">
        <label>Verifizierungs Code</label>
        <input class="form-control" name="tx_registration_userregistration[user][eMailVerified]" type="text">
    </div>

    <button type="button" class="btn btn-primary" onclick="validateEmailForm();">Bestätigen</button>
    <input class="small button" name="" value="Bestaetigen!" type="submit">
    <a class="small button" href="index.php?id=2&amp;tx_registration_userregistration%5Baction%5D=resendValidationCodeForm&amp;tx_registration_userregistration%5Bcontroller%5D=User&amp;cHash=89f3a9885d968a1cc58b78afeb462156">Code erneut anfordern</a>
</form>

如果我使用独立视图生成器,表单如下所示:

<form role="form" name="user" id="validateEmailForm" action="index.php?id=2&amp;tx_registration_%5Buser%5D=&amp;tx_registration_%5Baction%5D=validateEmail&amp;tx_registration_%5Bcontroller%5D=Standard&amp;cHash=1342195ecb09bfaa3eaaed53b5b6ca94" method="post">
    <div>
        <input name="__referrer[@extension]" value="Registration" type="hidden">
        <input name="__referrer[@controller]" value="Standard" type="hidden">
        <input name="__referrer[@action]" value="index" type="hidden">
        <input name="__referrer[arguments]" value="YTowOnt932be2d0043f353815075d39b8a8dcae00ef10469" type="hidden">
        <input name="__trustedProperties" value="a:2:{s:4:&quot;user&quot;;a:2:{s:12:&quot;eMailAddress&quot;;i:1;s:13:&quot;eMailVerified&quot;;i:1;}i:0;i:1;}34e733be32be90328d34d6e089e19ec1e4f4a54a" type="hidden">
    </div>

    <div class="form-group">
        <label>E-Mail Adresse</label>
        <input class="form-control" name="user[eMailAddress]" type="text">
    </div>

    <div class="form-group">
        <label>Verifizierungs Code</label>
        <input class="form-control" name="user[eMailVerified]" type="text">
    </div>

    <button type="button" class="btn btn-primary" onclick="validateEmailForm();">Bestätigen</button>
    <input class="small button" name="" value="Bestaetigen!" type="submit">
    <a class="small button" href="index.php?id=2&amp;tx_registration_%5Baction%5D=resendValidationCodeForm&amp;tx_registration_%5Bcontroller%5D=Standard&amp;cHash=0d47678ecec458d7283b92e15bd9d1d4">Code erneut anfordern</a>
</form>

如您所见,例如名称标签中的输入元素 "tx_registration_userregistration" 丢失,控制器无法使用它。

我使用独立视图生成器生成代码的方式是:

$View = $this->objectManager->get('TYPO3\CMS\Fluid\View\StandaloneView');   
$extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$templateRootPath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($extbaseFrameworkConfiguration['view']['templateRootPath']);
$templatePathAndFilename = $templateRootPath . 'tabControl/' . $templateName . '.html';
$View->setTemplatePathAndFilename($templatePathAndFilename);
$View->assignMultiple($variables);
$renderedView = $View->render();

return $renderedView;

有谁知道这个问题并且可能知道我该如何解决这个问题?

Action 的视图使用控制器的上下文,但独立视图默认没有任何上下文。您需要自己传递它,即在创建视图对象之后立即传递:

$View = $this->objectManager->get('TYPO3\CMS\Fluid\View\StandaloneView'); 
$View->setControllerContext($this->controllerContext);