ฉันมีคลาสเอนทิตีชื่อโฆษณา แต่ก็มีฟิลด์เช่น
id, banner, interstitial
ปัญหาคือเมื่อฉันพยายามสร้างแบบฟอร์มโดยใช้ฟิลด์ข้อความ 'แบนเนอร์' ของเอนทิตีนี้ไม่แสดง (ไม่แสดงผล) เฉพาะป้ายกำกับเท่านั้น
ฉันสังเกตเห็นว่ารหัสของ ฟิลด์คือ ad_banner ถ้าฉันเปลี่ยนรหัสในองค์ประกอบตรวจสอบเบราว์เซอร์ มันจะปรากฏขึ้น...
ad_banner คืออะไรใน Symfony ทำไมมันถึงซ่อนมันไว้?
ฉันไม่ ไม่อยากเปลี่ยนชื่อสนาม แล้วก็ไม่อยากเปลี่ยน id จากทวิด้วย เพราะอยากให้มันง่ายแบบนี้:
<div class="row">
<div class="col-md-6">
{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}
</div>
</div>
ฉันพยายามเปลี่ยน id ของฟิลด์จากตัวสร้างแบบฟอร์ม แต่ไม่ประสบความสำเร็จ ขอบคุณ!
คลาสโฆษณา
/**
* @var string
*
* @ORM\Column(name="banner", type="string", length=255, nullable=true)
*/
private $banner;
แบบฟอร์มประเภทโฆษณา
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('account', EntityType::class, [
'class' => 'AppBundle:Account',
'choice_label' => 'name',
'attr' => ['data-select' => 'true']
])
->add('banner', TextType::class, [
'attr' => [
'placeholder' => 'Banner Id...'
]
])
->add('interstitial', TextType::class, [
'attr' => [
'placeholder' => 'Interstitial Id...'
]
])
->add('submit', SubmitType::class, [
'label' => 'Create',
'attr' => [
'class' => 'btn btn-primary btn-sm'
]
])
;
}
HTML ที่สร้างขึ้น
<div class="form-group">
<label class="control-label required" for="ad_banner">Banner</label>
<input type="text" id="ad_banner" name="ad[banner]" required="required" placeholder="Banner Id..." class="form-control">
</div>
ฉันนำสไตล์นี้ออกไปเพราะฉันคิดว่าบางที js บางตัวอาจซ่อนมันไว้