gpt4 book ai didi

symfony - 在 SonataAdmin ListView 中显示名称而不是数据库值

转载 作者:行者123 更新时间:2023-12-02 17:07:59 25 4
gpt4 key购买 nike

当我尝试列出数据库中的记录时,我遇到了问题,因为我得到的值存储在行中,它是一个整数,但我想要字符串。我如何处理表格?这样:

protected function configureFormFields(FormMapper $form) {
$form
->add('no_order', null, array('label' => 'No. Order'))
->add('company', 'entity', array('class' => 'PL\CompanyBundle\Entity\Company', 'label' => 'Cliente'))
->add('business_case', null, array('label' => 'BC'))
->add('charge_status', 'choice', array('choices' => array(
"empty_value" => "Seleccione una opción",
"0" => "Ninguno",
"1" => "Proceso de Fabricacion",
"2" => "Pickup en destino",
"3" => "A la espera de recojo por cliente",
"4" => "Carga en transito",
"5" => "Carga arribada",
"6" => "En proceso de aduana",
"7" => "Entregado a cliente",
"8" => "En bodega"
), "required" => true, 'label' => 'Estado de la carga'))
->add('eta', null, array('label' => 'ETA', 'widget' => 'single_text', 'required' => false, 'attr' => array('class' => 'datepicker')))
->add('etd', null, array('label' => 'ETD', 'widget' => 'single_text', 'required' => false, 'attr' => array('class' => 'datepicker')))
->add('transport_media', 'choice', array('choices' => array("empty_value" => "Seleccione una opción", "0" => "EXW", "1" => "Maritimo", "2" => "Aereo"), "required" => true, 'label' => 'Via de Transporte'))
->add('incoterm', 'choice', array('choices' => array(
"empty_value" => "Seleccione una opción",
"0" => "Ninguno",
"1" => "EWX",
"2" => "FOB",
"3" => "CIF",
"4" => "DDP"
), "required" => true, 'label' => 'Incoterm'))
->add('comments', null, array('label' => 'Comentarios'))
->with('Documentos')
->add('medias', 'sonata_type_collection', array(
'required' => false), array(
'edit' => 'inline',
'inline' => 'table',
'sortable' => 'position'))
->end();
}

我将 charge_status (相当于 View 中的 BC)定义为选择,如何在 ListView 中显示字符串而不是值?请参阅附图以直观地了解问题

enter image description here

最佳答案

一种方法:

在实体中定义静态数组,例如:

<?php
class Entity
{
public static $chargeStatusList = array(
"0" => "Ninguno",
"1" => "Proceso de Fabricacion",
"2" => "Pickup en destino",
"3" => "A la espera de recojo por cliente",
"4" => "Carga en transito",
"5" => "Carga arribada",
"6" => "En proceso de aduana",
"7" => "Entregado a cliente",
"8" => "En bodega"
);

public function getChargeStatusValue()
{
return self::$chargeStatus[$this->charge_status];
}

}

在您的管理类(class)中

class YourAdmin extends Admin
{

....
use Path/To/Your/Entity;
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->add('chargeStatusValue', 'string', array('label' => 'Charge status'))

;
}

protected function configureFormFields(FormMapper $form)
{
....
->add('charge_status', 'choice', array('choices' => Entity::$chargeStatusList));
....
}
}

关于symfony - 在 SonataAdmin ListView 中显示名称而不是数据库值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21841898/

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