第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Symfony EasyAdminBundle 3 重寫(xiě) createIndexQuer

Symfony EasyAdminBundle 3 重寫(xiě) createIndexQuer

PHP
狐的傳說(shuō) 2023-10-15 14:49:19
EasyAdminBundle 文檔上說(shuō)例如,index() 操作調(diào)用名為 createIndexQueryBuilder() 的方法來(lái)創(chuàng)建用于獲取索引列表上顯示的結(jié)果的 Doctrine 查詢構(gòu)建器。如果您想自定義該列表,最好重寫(xiě) createIndexQueryBuilder() 方法而不是整個(gè) index() 方法。因此,讓我們想象一下,當(dāng)用戶被刪除時(shí),我在用戶實(shí)體中將字段 isDeleted 設(shè)置為 true。在索引頁(yè)面中,我想僅顯示 isDeleted = false 的用戶。如何為此目的重寫(xiě) createIndexQueryBuilder() ?這是方法 createIndexQueryBuilderpublic function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): QueryBuilder{    return $this->get(EntityRepository::class)->createQueryBuilder($searchDto, $entityDto, $fields, $filters);}我嘗試像這樣覆蓋它,但沒(méi)有成功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;}
查看完整描述

4 回答

?
MMMHUHU

TA貢獻(xiàn)1834條經(jīng)驗(yàn) 獲得超8個(gè)贊

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


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;

}


查看完整回答
反對(duì) 回復(fù) 2023-10-15
?
幕布斯7119047

TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超8個(gè)贊

這對(duì)我的 EasyAdmin 4.x 有用


use EasyCorp\Bundle\EasyAdminBundle\Orm\EntityRepository;


class CampaignCrudController extends AbstractCrudController

{

    public function __construct(EntityRepository $entityRepository)

    {

        $this->entityRepository = $entityRepository;

    }


    public function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): ORMQueryBuilder

    {

        $response = $this->entityRepository->createQueryBuilder($searchDto, $entityDto, $fields, $filters);

        $response->andWhere('entity.user = :user')->setParameter('user', $this->getUser());


        return $response;

    }


查看完整回答
反對(duì) 回復(fù) 2023-10-15
?
慕雪6442864

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊

EasyAdmin4解決方案


注意:關(guān)鍵字(別名)entity很重要


use Doctrine\ORM\QueryBuilder;


class ArticleCrudController extends AbstractCrudController

{

     ...


     public function configureFields(string $pageName): iterable

     {

          return [

                ...

                AssociationField::new('author')->setQueryBuilder(

                fn (QueryBuilder $queryBuilder) => $queryBuilder

                   ->leftJoin('entity.article', 'a')

                   ->andWhere('entity.isActive = 1')

                   ->andWhere('a.author is NULL')

                  ),

                ...

            ]

      }


      ...

}


查看完整回答
反對(duì) 回復(fù) 2023-10-15
?
慕碼人8056858

TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超6個(gè)贊

對(duì)于每個(gè)使用接受的答案并通過(guò)搜索找到以下 QueryException 的人:


QueryException 

Too many parameters: the query defines 1 parameters and you bound 3

EntityCrudController 內(nèi)的 EasyAdmin v3.x:


使用->andWhere()函數(shù)

使用實(shí)體。作為前綴(實(shí)際上,使用“實(shí)體”,不要替換為您的實(shí)體名稱)

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

{

    $response = $this->get(EntityRepository::class)->createQueryBuilder($searchDto, $entityDto, $fields, $filters);

    $response->andWhere('entity.isDeleted = 1');   

    return $response;

}


查看完整回答
反對(duì) 回復(fù) 2023-10-15
  • 4 回答
  • 0 關(guān)注
  • 194 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)