php – 如何在2个不同的表symfony中提交表单值
发布时间:2020-12-13 15:59:06 所属栏目:PHP教程 来源:网络整理
导读:我想提交一个表单并将值存储在2个不同的表中(位于同一个数据库中). 这是形式: div class="control-group" label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}Naam/label div class="controls" {{ form_widget(form.produ
|
我想提交一个表单并将值存储在2个不同的表中(位于同一个数据库中).
这是形式: <div class="control-group">
<label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>Naam</label>
<div class="controls">
{{ form_widget(form.product) }}
{{ form_errors(form.product) }}
</div>
</div>
<div class="control-group">
<label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>Aantal</label>
<div class="controls">
{{ form_widget(form.amount) }}
{{ form_errors(form.amount) }}
</div>
</div>
这是表单构建器: $builder->add("amount","number",array("label" => "Aantal"));
$builder->add("product","text",array("attr" => array("autocomplete" => "off","data-provide" => "typeahead","data-items" => "15","data-source" => $dataSource),'mapped' => false));
$builder->add("price",array("label" => "Aangepaste prijs",'mapped' => false));
这是实体的一部分: /**
* @var integer $id
*/
private $id;
/**
* @var integer $amount
*/
private $amount;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set amount
*
* @param integer $amount
* @return BookingEntry
*/
public function setAmount($amount)
{
$this->amount = $amount;
return $this;
}
/**
* Get amount
*
* @return integer
*/
public function getAmount()
{
return $this->amount;
}
这是ORM: type: entity
table: null
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
amount:
type: float
现在我想通过名称为’serial_nr’的表单添加一个输入字段.我想将此值存储在与“product”和“amount”存储在的表不同的表中. 有人能指出我正确的方向吗? 解决方法
你有’产品’和’价格’选项’mapped’=> false,所以如果在某个实体上定义了表单,则不保存此值,或者您自己执行此操作.
如果我理解正确,你有表(产品)列: >产品 而不是你想要与列相关的表格(product_serial): > product_id 并将此一个添加到您的表单的许多关系? manyToOne:
product:
targetEntity: Product
inversedBy: serials
joinColumn:
name: product_id
referencedColumnName: id
和桌上产品: oneToMany:
serials:
targetEntity: ProductSerial
mappedBy: product
并添加到表单集合字段’serials’. http://symfony.com/doc/current/reference/forms/types/collection.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
