Symfony2/Datatable Bundle - 错误:使用视图中的 id 在操作中使用“setDatatable


Symfony2/Datatable Bundle - error: set a datatable id in your action with "setDatatableId" using the id from in your view

我按照文档步骤在github上逐个导入Bundle AliDatatableBundle,除了安装中$ bin/vendor install的部分,因为使用Symfony2.6,没有必要这样做。

当我在控制器中创建函数并在树枝中创建渲染时,出现此错误:

呈现模板期间引发异常("否" 找到数据表的实例,您应该在 使用视图中的 id 对"setDatatableId"的操作 ") MySpaceGestionPatrimoinesBundle:Batiments:indexBatiments.html.twig at 第 37 行。

下面是控制器的代码:

/**
     * set datatable configs
     * 
     * @return 'Ali'DatatableBundle'Util'Datatable
     */
    private function _datatable()
    {
        $controller_instance = $this;
        return $this->get('datatable')
                    ->setDatatableId('batiments')
                    //->setEntity("MySpaceDatabaseBundle:Batiments", "b")                          
                    // replace "XXXMyBundle:Entity" by your entity
                    ->setFields(
                            array(
                                "Nom"          => 'b.nom',                        
                                // Declaration for fields: 
                                "Reférence"        => 'b.referencebatiment',                    
                                // "label" => "alias.field_attribute_for_dql"
                                "Ensembles"          => 'b.ensembles',  
                                "_identifier_"  => 'b.id')                          
                                // you have to put the identifier field without label. Do not replace the "_identifier_"
                            )
                    //->setWhere(                                                     
                    // set your dql where statement
                         //'x.address = :address',
                         //array('address' => 'Paris') 
                    //)
                    //->setOrder("x.created", "desc")                                 
                    // it's also possible to set the default order
                    ->setHasAction(true);                                           
                    // you can disable action column from here by setting "false".
    }
    /**
     * Grid action
     * @return Response
     */
    public function gridAction()
    {   
        return $this->_datatable()->execute();                                      
        // call the "execute" method in your grid action
    }
    /**
     * Lists all entities.
     * @return Response
     */
    public function indexAction()
    {
        $this->_datatable();                                                        
        // call the datatable config initializer
        return $this->render('MySpaceGestionPatrimoinesBundle:Batiments:indexBatiments.html.twig');                 
        // replace "XXXMyBundle:Module:index.html.twig" by yours
    }

然后是我的树枝的代码:

{% extends "MySpaceWelcomeBundle::layout.html.twig" %}
{% block content %}
<div class="jumbotron">
              <h4><u>Rechercher un bâtiment et ses affectations spécifiques:</u></h4>
              <br>                
              <div>
                {{ datatable({ 
                      'id' : 'batiments',
                      'js' : {
                          'sAjaxSource' : path('mySpace_formulaire_recherche_batiments')
                      }
                  })
              }}
              </div>
            </div>
{% endblock %}

真的不明白,有人可以帮助我解决这个问题吗?

我已经清除了缓存,安装了资产并从头开始接管了文档,我不明白。

提前谢谢你。

似乎一切都很好。如果您遵循AliBundle的文档,我在这里看不到问题。尝试在这里使用 Jquery 数据表,我认为安装更容易,如果要在 Symfony 中管理您的实体,对您的项目更好。

如果您对Jquery DataTables有疑问,请随时询问,我也在Symfony项目中使用它。