Php Symfony2/Datatable Bundle-错误:在操作中使用“设置Datatable id”;setDatatableId";在视图中使用来自的id

Php Symfony2/Datatable Bundle-错误:在操作中使用“设置Datatable id”;setDatatableId";在视图中使用来自的id,php,symfony,datatable,twig,bundle,Php,Symfony,Datatable,Twig,Bundle,我在github上按照文档步骤逐个导入捆绑包,除了中的部件$bin/vendor install,因为使用Symfony2.6,不需要这样做 当我在我的控制器中创建函数,并在我的细枝中创建渲染时,我有以下错误: /** * set datatable configs * * @return \Ali\DatatableBundle\Util\Datatable */ private function _datatable() {

我在github上按照文档步骤逐个导入捆绑包,除了中的部件
$bin/vendor install
,因为使用Symfony2.6,不需要这样做

当我在我的控制器中创建函数,并在我的细枝中创建渲染时,我有以下错误:

/**
     * 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 %}
在呈现模板期间引发了异常(“否”) 找到datatable的实例时,应在数据库中设置datatable id 使用视图中的id“setDatatableId”执行的操作 MySpaceGestinationPatrimoinesBundle:Batiments:indexBatiments.html.twig位于 第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 %}
然后是我的小树枝的代码:

/**
     * 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 %}
{%extends“MySpaceWelcomeBundle::layout.html.twig”%}
{%block content%}
关于时间和行为规范的建议:

{{数据表({ “id”:“batiments”, ‘js’:{ “sAjaxSource”:路径(“mySpace\u formulaire\u recherche\u batiments”) } }) }} {%endblock%}
我真的不明白,有人能帮我解决这个问题吗?

我已经清除了缓存,安装了资产,从一开始就重新接管了文档,我不明白


提前谢谢你。

看起来一切都很好。如果你遵循aliBundle的文档,我看不出这里有什么问题。尝试使用jquerydatatable,我认为安装更容易,如果要在Symfony中管理实体,则对您的项目更有利


如果您对Jquery DataTables有任何疑问,请不要犹豫,我也将它用于Symfony项目。

我将尝试输入Jquery DataTables。谢谢你的帮助。如果我有问题,我会问你。@Julien,不客气,不要犹豫,我的项目也是这样。@Julien,这里有一些链接可以帮助你解决应用程序所需的不同情况:这里也是:我尝试使用你给我的代码。谢谢你的帮助。这有助于我获得更好的搜索结果。