脚本宝典收集整理的这篇文章主要介绍了php – 我可以使用表单构建器中的查询以symfony形式获取过滤收集,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
->add('pizza','entITy',array( 'class' => 'Acme\PizzaBundle\Entity\Pizza','query_builder' => function ($repository) { return $repository->createQueryBuilder('p')->orderBy('p.name','ASC'); },))
我可以在收藏中做这样的事情吗?
->add('userTasks','collection',array('tyPE' => new UserTaskType(),'class' => 'acme\myBundle\Entity\UserTask',))
我必须过滤掉一些实体,解决的关键是在实体类中创建set / get方法返回所需的集合.
在我的情况下,看起来像这样
/** * Set values * * @param ArrayCollection $values * @return Attribute */ public function setCustomValues($values) { $result = $this->getNotCustomValues(); foreach ($values as $value) { $value->setattribute($this); $result->add($value); } $this->values = $result; return $this; } /** * Get values * * @return \Doctrine\Common\Collections\Collection */ public function getCustomValues() { $result = new ArrayCollection(); foreach ($this->values as $value) { if($value->getCustom()) { $result->add($value); } } return $result; }
而当创建表单时,字段的名称是“customvalues”而不是“values”所以我的集合只包含自定义字段true的值.
以上是脚本宝典为你收集整理的php – 我可以使用表单构建器中的查询以symfony形式获取过滤收集全部内容,希望文章能够帮你解决php – 我可以使用表单构建器中的查询以symfony形式获取过滤收集所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。