Symfony 4,删除表单中的空白字段

时间:2018-09-14 17:51:59

标签: forms symfony4

 ->add('bill', EntityType::class, [
                'class' => \App\Entity\Bill::class,
                'attr' => [
                    'class' => "js-example-basic-single",
                ],
                'label' => false,
                'required' => true,
                'choice_label' => function ($bill) {
                    $sumPrice = 0;
                    $sumPayment = 0;
                    foreach ($bill->getCost() as $item) {
                        $sumPrice = $sumPrice + $item->getPrice();
                        foreach ($bill->getPayment() as $pay) {
                            $sumPayment = $sumPayment + $pay->getMoney();
                        }
                        $sum = $sumPayment - $sumPrice;
                        if ($sum != 0) {
                            return
                                $bill->getPlayers()->getName() . " " .
                                $sum;
                        }
                    }
                }
            ]);

一切正常,我只得到总和等于0的玩家,其余的玩家,我没有玩家的名字(没关系),但是我有空格,而且我不知道如何删除它

0 个答案:

没有答案