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 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥20 使用Photon PUN2解决游戏得分同步的问题
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM