APY / APYDataGridBundle

Symfony Datagrid Bundle
MIT License
493 stars 343 forks source link

Bug template rendering ? #976

Closed Quovandius closed 7 years ago

Quovandius commented 7 years ago

Hello,

Its my first time with this bundle.

I have followed the quick tutorial for a first implementation, and i have this error :

Error: Call to a member function getParent() on boolean

The stack trace :

in vendor\apy\datagrid-bundle\Twig\DataGridExtension.php at line 457   -
  $template = $environment->loadTemplate($theme); 
        while ($template !== null) { 
            $this->templates[] = $template; 
            $template = $template->getParent([]); 
        } 
        return $this->templates; 

For my code i have copy paste code of tutorial.

Mycontroller :

/**
     * @Security("has_role('ROLE_APP')")
     * @Route("/datatable", name="app_order_datatable")
     */
    public function datatableAction()
    {
        $source = new Entity('AppOrderBundle:Order');
        $grid = $this->get('grid');
        $grid->setSource($source);

        return $grid->getGridResponse('AppOrderBundle:Order:datatable.html.twig');
    }

my entity :

/**
 * Order
 *
 * @ORM\Table(name="app_order")
 * @ORM\Entity(repositoryClass="App\OrderBundle\Repository\OrderRepository")
 * @ORM\HasLifecycleCallbacks()
 * @GRID\Source(columns="id, state, total, nbPeople")
 */
class Order

I have no idea where is the problem ... If anyone have an idea plz. Thx for your help.

DonCallisto commented 7 years ago

Umh, I suppose is your project's template issue. Could you try to VarDump $template variable in each while iteration and paste here the results?

Thanks.

Quovandius commented 7 years ago

Sorry i'm not clear. Its template var of datagrid-bundle :

in vendor\apy\datagrid-bundle\Twig\DataGridExtension.php at line 457 
      $template = $environment->loadTemplate($theme); 
        while ($template !== null) { 
            $this->templates[] = $template; 
            $template = $template->getParent([]); 
        } 
        return $this->templates; 

When i try not print the grid in view, i haven't error. And i add this line on my view : {{ grid(grid) }} I have this error ?_?

DonCallisto commented 7 years ago

I mean this template: AppOrderBundle:Order:datatable.html.twig

Quovandius commented 7 years ago

Ok sorry

here my view :

{% block app_list %}

    {{ grid(grid) }}
    {{ dump(grid) }}

    <a class="btn btn-primary btn-circle btn-lg" href="{{ path('app_order_new') }}"
       title="{{ 'link.new'|trans }}"><i class="fa fa-plus"></i></a>
{% endblock app_list %}
DonCallisto commented 7 years ago

@Quovandius I've requested the dump of $template variable in this while loop

while ($template !== null) { 
  $this->templates[] = $template; 
  $template = $template->getParent([]); 
} 

I think your error could be in template hierarchy or something like this but I can't be sure if you don't provide those informations.

Quovandius commented 7 years ago

Ok i understand BUT the $template var is not my var. The error is on APYDataGridBundle file, and $template var is in bundle code. Its not my code.

I have add a var dump ion code bundle. 1st return :

C:\MySoftwares\wamp\www\App\vendor\apy\datagrid-bundle\Twig\DataGridExtension.php:456:
object(__TwigTemplate_c94809d049e58cb9c73fd999c4720c57edb198c41a6903da29df1b3f3db0a6a1)[8128]
  protected 'parent' => boolean false
  protected 'parents' => 
    array (size=0)
      empty
  protected 'env' => 
    object(Twig_Environment)[571]
      protected 'charset' => string 'UTF-8' (length=5)
      protected 'loader' => 
        object(Symfony\Bundle\TwigBundle\Loader\FilesystemLoader)[585]
          protected 'locator' => 
            object(Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator)[570]

2nd return: C:\MySoftwares\wamp\www\App\vendor\apy\datagrid-bundle\Twig\DataGridExtension.php:456:boolean false

theses information can help you ?

DonCallisto commented 7 years ago

The $template var IS indeed your var, as it is passed by the call $grid->getGridResponse('AppOrderBundle:Order:datatable.html.twig');

So it seems like that there's an issue with the !== null check.

I'll fix in the next hours and release a bug fix version.

DonCallisto commented 7 years ago

@Quovandius this should fix the error.

Could you try to download master branch (before I tag a release) and checkout if it works?

Thank you.

Quovandius commented 7 years ago

@DonCallisto I have try to replace the line and this should work. I have comment your commit. Very thanks for your help and your patience ;)

DonCallisto commented 7 years ago

@Quovandius I'm gonna release a bug fix version

DonCallisto commented 7 years ago

Here it is

vinzcoco commented 6 years ago

Hello, I have an other bug :

Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function getParent() on boolean in /var/www/html/vendor/apy/datagrid-bundle/Grid/Export/Export.php:465 Stack trace: #0 /var/www/html/vendor/apy/datagrid-bundle/Grid/Export/Export.php(447): APY\DataGridBundle\Grid\Export\Export->getTemplatesFromString('@WinzanaCore/Gr...') #1 /var/www/html/vendor/apy/datagrid-bundle/Grid/Export/Export.php(425): APY\DataGridBundle\Grid\Export\Export->setTemplate('@WinzanaCore/Gr...') #2 /var/www/html/vendor/apy/datagrid-bundle/Grid/Export/Export.php(406): APY\DataGridBundle\Grid\Export\Export->getTemplates() #3 /var/www/html/vendor/apy/datagrid-bundle/Grid/Export/Export.php(255): APY\DataGridBundle\Grid\Export\Export->renderBlock('grid_titles', Array) #4 /var/www/html/vendor/apy/datagrid-bundle/Grid/Export/Export.php(185): APY\DataGridBundle\Grid\Export\Export->getGridTitles() #5 /var/www/html/vendor/apy/datagrid-bundle/Grid/Export/ExcelExport.php(26): APY\DataGridBundle\Grid\Export\Export->getGrid in /var/www/html/vendor/apy/datagrid-bundle/Grid/Export/Export.php on line 465

To fix it i make : `

protected function getTemplatesFromString($theme)
{
    $templates = [];
    $template = $this->twig->loadTemplate($theme);
    while (null !== $template and !is_bool($template)) {
        $templates[] = $template;
        $template = $template->getParent([]);
    }
    return $templates;
}

` It's correct ? thank's

DonCallisto commented 6 years ago

This won't fix the issue. BTW we already have a fix so my suggestion is to move to 3.1