PHP中未知的“ rootform”测试呈现表单

时间:2019-01-14 16:29:23

标签: php symfony twig slim-3

我正在尝试让Symfony Forms(与Twig Bridge一起使用),Slim和Twig一起很好地玩耍,但看不到成功。从我看到的内容来看,我具有工作的形式方面,即创建了表单,createView()方法按预期进行,我可以将其偏移到Twig模板中并使用{{ dump(form) }}进行查看一切都会从那里开始。

我有一个因素可以在Twig中创建用于渲染表单的相关内容,并设置默认模板等-所有这些似乎都可以正常工作,但是由于某些原因,当我退出并渲染表单时,出现以下错误:

Type: Twig_Error_Syntax
Message: Unknown "rootform" test.
File: /var/www/mulligan/vendor/symfony/twig-bridge/Resources/views/Form/form_div_layout.html.twig
Line: 22

我已经检查确定FormExtension正在加载,并且正在加载它,并且正在定义测试函数等(其中之一是rootform),并且一切似乎都工作正常。这基本上就是我用来定义FormFactory的因素(也可以根据需要处理Twig的东西):

    /**
     * @return FormFactoryInterface|null
     * @throws \ReflectionException
     */
    public function initialiseFactory(): ?FormFactoryInterface
    {
        $csrfGenerator = new UriSafeTokenGenerator();
        $csrfStorage   = new NativeSessionTokenStorage();
        $csrfManager   = new CsrfTokenManager($csrfGenerator, $csrfStorage);

        $defaultFormTheme          = 'form_div_layout.html.twig';
        $appVariableReflection     = new ReflectionClass(AppVariable::class);
        $vendorTwigBridgeDirectory = \dirname($appVariableReflection->getFileName());
        $viewsDirectory            = PROJECT_ROOT . '/templates/form';

        $twig = $this->getTwigView();

        $twigEnv       = new Environment(new FilesystemLoader([
            $viewsDirectory,
            $vendorTwigBridgeDirectory . '/Resources/views/Form'
        ]));
        $formEngine = new TwigRendererEngine([$defaultFormTheme], $twigEnv);

        $twig->getEnvironment()->addRuntimeLoader(new FactoryRuntimeLoader([
            FormRenderer::class => function () use ($formEngine, $csrfManager) {
                return new FormRenderer($formEngine, $csrfManager);
            }
        ]));

        $twig->addExtension(new FormExtension());

        $validator = Validation::createValidator();

        // Set up the Form component
        $formFactory = Forms::createFormFactoryBuilder()
                            ->addExtension(new HttpFoundationExtension())
                            ->addExtension(new CsrfExtension($csrfManager))
                            ->addExtension(new ValidatorExtension($validator))
                            ->getFormFactory();

        $this->setFactory($formFactory);

        return $this->getFactory();
    }

在执行此操作时,是否有人对我可能缺少的东西或可能未初始化的东西有任何想法-我通常不会使用Symfony Forms等,因此不确定问题可能在哪里。

NB:composer.json用于版本等:

    "slim/slim": "^3.11",
    "slim/php-view": "2.1.*",
    "symfony/form": "^4.2",
    "symfony/security-csrf": "^4.2",
    "symfony/twig-bridge": "^4.2",
    "symfony/validator": "^4.2",
    "symfony/http-foundation": "^4.2",
    "slim/twig-view": "^2.4"

预先感谢

0 个答案:

没有答案