简体   繁体   中英

Symfony2 : Fatal Error: Call to a member function loadTemplate() on a non-object

I try to upgrade my symfony2 project to symfony3 (I have moved from twig 1.2 to twig 2.0, and upgrade some other bundles like fos_user bundle, braincrafted/bootstrap bundle... ) and I encounter an error :

Fatal Error: Call to a member function loadTemplate() on a non-object 

The detailed log is :

DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController".
CRITICAL - Fatal Error: Call to a member function loadTemplate() on a non-object
CRITICAL - Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalErrorException: "Error: Call to a member function loadTemplate() on a non-object" at /my/path/Symfony/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php line 156 

The error triggers for the first template containing Form blocks. If I remove the form blocks (eg {{form_start}} or {{form_widget(...)}}), the errors appears for another template with form elements.

Does anyone have an idea to help me ?

Thanks in advance.

I have disabled BraincraftedBootstrapBundle. I have added a print_r in TwigRendererEngine.php

protected function loadResourcesFromTheme($cacheKey, &$theme)
{
    print_r($theme); // added for debug
    if (!$theme instanceof \Twig_Template) {
        /* @var \Twig_Template $theme */
        $theme = $this->environment->loadTemplate($theme);
    }
    ...

to get the name of the template which trigger the error.

It seems to be "form_div_layout.html.twig"

When BraincraftedBootstrapBundle is activate, the template name is BraincraftedBootstrapBundle:Form:bootstrap.html.twig (which use form_div_layout.html.twig)

Does this could help you ? Thanks

I found a fix for the while

I have changes my composer from "sensio/distribution-bundle": "5.0", to "sensio/distribution-bundle": "~4.0", it seems that there was some big change in the code...

I am still not in version 3.0 but now it works again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM