2
卡住了一個惱人的問題,我覺得我需要另一雙眼睛。輸入無法在symfony和formbuilder上提交
出於某種原因,我無法獲得此控制器在Symfony中找到的formbuilder生成字段。
下面是相關一塊控制器
$barcode = $request->get('barcode');
$em = $this->getDoctrine()->getManager();
//this checks for whether an item still exists
$items = $em->getRepository('Bundlename:Items\Item')
->itemsNotDisposedByBarcode($barcode);
if ($items) { .... do stuff ...}
else { $this->get('bundle.flashbag')
->addError('Item not found.');
沒有什麼事似乎被發現的。
我測試這個運行條件關閉的$barcode
所以這是非常肯定的樹枝或形式(換句話說,我敢肯定,這不是itemsNotDisposedByBarcode
,似乎有什麼不妥查詢)
這裏的formbuilder的樣子:
class DisposeItemBarcodeType extends AbstractType
{
protected $editors = array();
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('barcode','text',
array('required' => false));
}
public function getName()
{
return 'bundle_items_item';
}
}
我一直在想這可能是某種程度上的樹枝,但是它看起來罰款我的眼睛;不知道它是不是Formbuilder,或者如果我需要破解它,只是使用常規的形式。下面是我對這個:
{{ form_start(form, {'action': path('bundle_item_dispose_post'),'attr': {'id': 'dispose-item-form','novalidate': 'novalidate'}}) }}
{{ form_errors(form) }}
<section>
<div class="panel-body" id="barcode">
{{ form_row(form.barcode, {'attr': {'name':'barcode','class': 'barcode-field', 'autofocus': true}})}}
</div>
我有一種感覺,我失去了一些東西很明顯,但我的眼睛沒有看到它。
=== 編輯:從下面
的幫助解決了原來formbuilder做一些tokening,所以我只需要做到這一點:
$barcode = $postData['bundle_items_item']['barcode'];
謝謝!我甚至用'$ barcode = $ request-> request-> get('barcode');'那個方向去了''這似乎已經完成了這個技巧至少在這裏(對下一個錯誤lol) – nomistic
實際上是nope。我只是意識到它不能識別第二行中的條形碼,這似乎是上述枝條的問題。你能看到它沒有看到條形碼嗎?是否與formbuilder有關?這對我來說似乎很難。 – nomistic
嘗試var_dump($ postData)看看 –