duanque19820925 2019-01-14 16:29 采纳率: 0%
浏览 44

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

I'm trying to get Symfony Forms (with Twig Bridge), Slim and Twig playing nicely together but can't see to do it with any success. From what I can see I have the form aspect of things working, in that the form is created, the createView() method does as it should and I can offset it into a Twig template and use {{ dump(form) }} to see that everything is going as it should from there.

I have a factor which creates the relevant stuff for rendering forms in Twig and set s the default template etc - all of which seems to be working, but for some reason when I ret and render the form, I get the following error:

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

I've checked to make sure the FormExtension is loading and it is, and it's definining the test functions etc (one of which is rootform) and all seems to be working fine. This is basically the Factor I'm using to define the FormFactory (and handle the Twig stuff as necessary too):

    /**
     * @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();
    }

Has anyone got any thoughts on what I may be missing, or anything which may be failing to initialise whilst doing this - I wouldn't normally use Symfony Forms etc, so unsure where the issue may lie.

NB: composer.json for versions etc:

    "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"

thanks in advance

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥30 python代码,帮调试,帮帮忙吧
    • ¥15 #MATLAB仿真#车辆换道路径规划