Zend framework2 Zend framework 2-如何使用简单数组绑定表单数据
我正在寻找一个干净的解决方案,如何仅用数组绑定表单数据? 我试图转换为stdClass对象,但没有结果Zend framework2 Zend framework 2-如何使用简单数组绑定表单数据,zend-framework2,zend-form,Zend Framework2,Zend Form,我正在寻找一个干净的解决方案,如何仅用数组绑定表单数据? 我试图转换为stdClass对象,但没有结果 $product = new Product(); $product->exchangeArray(get_object_vars($productData)); $form=new ProductForm(); $form->bind($product); $form->get('submit')->
$product = new Product();
$product->exchangeArray(get_object_vars($productData));
$form=new ProductForm();
$form->bind($product);
$form->get('submit')->setValue('Save');
形式
$product = new Product();
$product->exchangeArray(get_object_vars($productData));
$form=new ProductForm();
$form->bind($product);
$form->get('submit')->setValue('Save');
在编辑操作中:
$form = new ProductForm();
$form->bind($productData);
$product = new Product();
$product->exchangeArray(get_object_vars($productData));
$form=new ProductForm();
$form->bind($product);
$form->get('submit')->setValue('Save');
$productData是一个数组,如下所示:
array (size=52)
'product_id' => string '6' (length=1)
'sku' => string '10/10/1992' (length=10)
'set' => string '4' (length=1)
'type' => string 'simple' (length=6)
'categories' =>
array (size=1)
0 => string '3' (length=1)
'websites' =>
array (size=1)
0 => string '1' (length=1)
'type_id' => string 'simple' (length=6)
'name' => string 'Front fog lights set crystal smoked VW Golf MK2, Jetta MK2' (length=58)
'description' => string 'Front fog lights set crystal smoked VW Golf MK2, Jetta MK2' (length=58)
'short_description' => string 'Front fog lights set crystal smoked VW Golf MK2, Jetta MK2' (length=58)
'weight' => string '2.0000' (length=6)
'old_id' => null
'news_from_date' => null
'news_to_date' => null
'status' => string '1' (length=1)
'url_key' => string 'front-fog-lights-set-crystal-smoked-vw-golf-mk2-jetta-mk2' (length=57)
'url_path' => string 'front-fog-lights-set-crystal-smoked-vw-golf-mk2-jetta-mk2.html' (length=62)
'visibility' => string '4' (length=1)
'category_ids' =>
array (size=1)
0 => string '3' (length=1)
'required_options' => string '0' (length=1)
'price' => string '49.9900' (length=7)
...
$product = new Product();
$product->exchangeArray(get_object_vars($productData));
$form=new ProductForm();
$form->bind($product);
$form->get('submit')->setValue('Save');
关于,更改此
$form = new ProductForm();
$form->bind($productData);
$product = new Product();
$product->exchangeArray(get_object_vars($productData));
$form=new ProductForm();
$form->bind($product);
$form->get('submit')->setValue('Save');
对此
$product = new Product();
$product->exchangeArray(get_object_vars($productData));
$form=new ProductForm();
$form->bind($product);
$form->get('submit')->setValue('Save');
给我们你的表格,给我们你的数组,告诉我们什么不起作用,告诉我们你希望什么起作用。。。不要让我们为您做这些工作…希望这些信息会更有用。使用bindValues($array)并且我认为您应该使用bind($object)$object这里应该是您的stdClass,也可能您需要在产品表单上设置或()。我不是用stdClass这样做的,所以我不是100%确定。我是这样理解的:$product=新产品()$product->exchangeArray($productInfo)$form=新产品form()$表单->绑定($product);我获取产品实体,然后使用exchangeArray方法,并将产品对象传递给表单:)