【问题标题】:Doctrine 2 result caching in Symfony with form type entity使用表单类型实体在 Symfony 中缓存 Doctrine 2 结果
【发布时间】:2011-12-17 00:27:35
【问题描述】:
我在 docrine 中使用 APC 结果缓存,并在所有网站页面中都有类型实体的过滤器表单并希望缓存它,但是当我将 useResultCache() 添加到方法时出现异常
必须管理传递给选择字段的实体
示例
...->getQuery()->useResultCache(true, null, 'someindex')->getResult()
但所有没有form 和entity type 的操作都可以正常工作。
有什么想法吗?
【问题讨论】:
标签:
forms
symfony
doctrine-orm
【解决方案1】:
不知道你是否想出了办法,但这是我的做法(花了半天时间弄清楚)。
/* in FormType.php */
public function buildForm(FormBuilderInterface $builder, array $options)
{
$items = $options['entity_repository']
->findItems()
->useResultCache(true, 3600, 'my_cache')
->getResult();
$choice_list = new ObjectChoiceList($items, 'name', array(), null, 'id');
$builder->add('item', 'entity', array(
'class' => 'MyBundle:Items',
'multiple' => true,
'expanded' => true,
'choice_list' => $choice_list,
));
}