gpt4 book ai didi

php - Symfony EasyAdminBundle 3 覆盖 createIndexQueryBuilder()

转载 作者:行者123 更新时间:2023-12-04 15:58:29 32 4
gpt4 key购买 nike

它在 EasyAdminBundle 文档上说

For example, the index() action calls to a method named createIndexQueryBuilder() to create the Doctrine query builder used to get the results displayed on the index listing. If you want to customize that listing, it’s better to override the createIndexQueryBuilder() method instead of the entire index() method.


因此,让我们想象一下,当用户被删除时,我的用户实体中的字段 isDeleted 设置为 true。在索引页面中,我只想显示 isDeleted = false 的用户。
为此,如何覆盖 createIndexQueryBuilder()?
这是方法 createIndexQueryBuilder

public function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): QueryBuilder
{
return $this->get(EntityRepository::class)->createQueryBuilder($searchDto, $entityDto, $fields, $filters);
}
我试图像这样覆盖它,但它没有用

public function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): QueryBuilder
{
$response = $this->get(EntityRepository::class)->createQueryBuilder($searchDto, $entityDto, $fields, $filters);
$response->where('isDeleted', true);
return $response;
}

最佳答案

您只需要添加 entity.在 where 子句中 :)

public function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): QueryBuilder
{
parent::createIndexQueryBuilder($searchDto, $entityDto, $fields, $filters);

$response = $this->get(EntityRepository::class)->createQueryBuilder($searchDto, $entityDto, $fields, $filters);
$response->where('entity.isDeleted = 1');

return $response;
}

关于php - Symfony EasyAdminBundle 3 覆盖 createIndexQueryBuilder(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63432424/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com