程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Symfony 4 Form Builder EntityType 查询所有位置但不是默认值大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Symfony 4 Form Builder EntityType 查询所有位置但不是默认值?

开发过程中遇到Symfony 4 Form Builder EntityType 查询所有位置但不是默认值的问题如何解决?下面主要结合日常开发的经验,给出你关于Symfony 4 Form Builder EntityType 查询所有位置但不是默认值的解决方法建议,希望对你解决Symfony 4 Form Builder EntityType 查询所有位置但不是默认值有所启发或帮助;

我在使用 ENtityType 的表单构建器上遇到问题,我需要从数据库中返回所有活动记录(c.status = 活动),其中一条非活动记录(c.ID = 200)。

我是 symfony 的新手

public function buildForm(FormBuilderInterface $builder,array $options)
    {
        $builder
            ->add('merchant_API_biller',EntityType::class,[
                'label' => 'Choose API ProvIDer','placeholder' => 'SELEct API ProvIDer','required' => false,'class' => MerchantAPIBiller::class,'query_builder' => function (EntityRepository $entityRepository) {

                    return $entityRepository->createqueryBuilder('c')
                        ->anDWhere('c.status = active WITH INACTIVE c.ID = 200')
                        ->anDWhere('c.accountMode = :mode')
                        ->setParameter('mode','live')
                        ->addOrderBy('c.name','ASC');
                },'choice_label' => function (MerchantAPIBiller $biller,$key,$indeX) {
                    // Hold Merchant ProvIDer
                    $provIDer = ($biller->getMerchantAPIProvIDer()) ? ' | '.$biller->getMerchantAPIProvIDer()->getname() : null;

                    return ''.$biller->getname().' - '.$biller->getCurrecyname().''.$provIDer.'';
                },'choice_value' => 'IDentify','choice_attr' => function (MerchantAPIBiller $biller,$indeX) {
                    return [
                        'data-name' => $biller->getname(),'data-currencyID' => $biller->getCurrency()->getID(),'data-hasamountfixed' => ($biller->getIsamountFixed() == truE) ? 1 : 0,'data-minamount' => $biller->getMinamount(),'data-maxamount' => $biller->getMaxamount(),'data-hasdenomination' => ($biller->getDenomination()) ? 1 : 0,'data-denomination' => ($biller->getDenomination()) ? implode(',',$biller->getDenomination()) : null,'data-desc' => $biller->getDescription(),];
                },]);

我需要所有记录返回 c.ID = 200(它的非活动记录),其他非活动记录保持非活动状态而不显示在结果中。

谢谢

解决方法

尝试更改此行:

->andWhere('c.status = active WITH INACTIVE c.id = 200')

为此:

->andWhere('c.status = active OR c.id = 200')

大佬总结

以上是大佬教程为你收集整理的Symfony 4 Form Builder EntityType 查询所有位置但不是默认值全部内容,希望文章能够帮你解决Symfony 4 Form Builder EntityType 查询所有位置但不是默认值所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:4Builder