Symfony2 / Datatable Bundle - 错误:使用“setDatatableId”在操作中设置一个datatable id使用您的视图中的id [英] Symfony2/Datatable Bundle - error: set a datatable id in your action with "setDatatableId" using the id from in your view
问题描述
我将 github 导入捆绑包 AliDatatableBundle , strong>遵循文档步骤,除了 $ bin / vendor install /master/README.md#installation-1rel =nofollow>安装,因为使用Symfony2.6,没有必要这样做。
当我在我的控制器中创建功能,并在我的枝条中渲染时,我有这个错误:
在渲染模板期间抛出异常(No
实例为datatable发现,您应该使用setDatatableId使用您的视图中的id将
操作中的datatable id设置为$)
MySpaceGestionPatrimoinesBundle: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)
//由您的实体替换XXXMyBundle:Entity
- > setFields(
array(
Nom=>'b.nom',
//字段声明:
Reférence=>'b.referencebatiment',
//label=>alias.field_attribute_for_dql
Ensembles=>' b.ensembles',
_identifier_=>'b.id')
//你必须把标识符字段没有实验室el。不要替换_identifier_
)
// - > setWhere(
//设置你的dql where语句
//'x.address =:address',
// array('address'=> 'Paris')
//)
//->setOrder(\"x.created,desc)
//也可以设置默认顺序
- > setHasAction(true);
//您可以通过设置false从此禁用操作列。
}
/ **
*网格动作
* @return响应
* /
public function gridAction()
{
return $ this-> _datatable() - > execute();
//调用网格动作中的execute方法
}
/ **
*列出所有实体。
* @return响应
* /
public function indexAction()
{
$ this-> _datatable();
//调用datatable config initializer
return $ this-> render('MySpaceGestionPatrimoinesBundle:Batiments:indexBatiments.html.twig');
//替换XXXMyBundle:Module:index.html.twigby yours
}
然后我的 twig 的代码:
{%extendsMySpaceWelcomeBundle :: layout.html.twig%}
{%block content%}
< div class =jumbotron>
< h4>< u> Rechercher unbâtimentet ses affectationsspécifiques:< / u>< / h4>
< br>
< div>
{{datatable({
'id':'batiments',
'js':{
'sAjaxSource':path('mySpace_formulaire_recherche_batiments')
}
})
}}
< / div>
< / div>
{%endblock%}
我真的不明白,有人可以帮助我解决这个问题?
我已经清除缓存,安装资产,并从头开始接管文档,我不明白。 / p>
提前谢谢。
似乎一切都很好。我看不到这里的问题,如果你遵循aliBundle的文档。尝试使用Jquery数据表这里,如果要管理您的项目,安装更简单,我认为和更好的项目Symfony中的实体。
如果您对Jquery DataTables有任何疑问,请不要犹豫,我也将其用于Symfony项目。
I import the Bundle AliDatatableBundle on github following the doc step one by one except the part $ bin/vendor install
in the installation because with Symfony2.6, there's no need to do this.
When I create the function in my controller, and the rendering in my twig, I have this error:
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.
Here's the code for the controller:
/**
* 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
}
And then the code for my 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 %}
I really don't understand, someone could help me to fix this?
I have already clear the cache, install assets and took over again from the beginning the doc, I do not understand.
Thank you in advance.
It seems like everything was good. I can't see the problem here, if you followed the doc of aliBundle. Try using the Jquery datatable here, the installation is easier I think and better for your project if it's to manage your entities in Symfony.
If you have questions for Jquery DataTables, don't hesitate to ask, I'm using it for a Symfony project too.
这篇关于Symfony2 / Datatable Bundle - 错误:使用“setDatatableId”在操作中设置一个datatable id使用您的视图中的id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!