【问题标题】: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()

但所有没有formentity 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,
    ));
}

【讨论】:

    猜你喜欢
    • 2015-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-03
    • 2016-04-29
    • 1970-01-01
    • 2016-06-26
    • 2016-09-27
    相关资源
    最近更新 更多