Symfony2/Datatable Bundle - error: set a datatable id in your action with "setDatatableId" using the id from in your view
Symfony2/Datatable Bundle - error: set a datatable id in your action with "setDatatableId" using the id from in your view
我导入 Bundle AliDatatableBundle on github following the doc step one by one except the part $ bin/vendor install
in the installation 因为有了 Symfony2.6,就不需要这样做了。
当我在我的控制器中创建函数并在我的树枝中进行渲染时,我有这个 错误:
An exception has been thrown during the rendering of a template ("No
instance found for datatable, you should set a datatable id in your
action with "setDatatableId" using the id from your view ") in
MySpaceGestionPatrimoinesBundle:Batiments:indexBatiments.html.twig at
line 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
}
然后是我的 twig 的代码:
{% 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 数据表 here,如果要在 Symfony 中管理您的实体,我认为安装更容易并且对您的项目更好。
如果您对 Jquery DataTables 有任何疑问,请不要犹豫,我也在将它用于 Symfony 项目。
我导入 Bundle AliDatatableBundle on github following the doc step one by one except the part $ bin/vendor install
in the installation 因为有了 Symfony2.6,就不需要这样做了。
当我在我的控制器中创建函数并在我的树枝中进行渲染时,我有这个 错误:
An exception has been thrown during the rendering of a template ("No instance found for datatable, you should set a datatable id in your action with "setDatatableId" using the id from your view ") in MySpaceGestionPatrimoinesBundle:Batiments:indexBatiments.html.twig at line 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
}
然后是我的 twig 的代码:
{% 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 数据表 here,如果要在 Symfony 中管理您的实体,我认为安装更容易并且对您的项目更好。
如果您对 Jquery DataTables 有任何疑问,请不要犹豫,我也在将它用于 Symfony 项目。