我在产品和属性之间有多对多关系。我在我的产品表单中使用embedRelation()来编辑产品,它是属性。属性包括导致我的问题的图像。每次保存表单时,即使未上传文件,updated_at列也会更新文件属性。Symfony:从表单中排除空值save
因此,我想在保存表单时排除空的属性。
我正在使用Symfony 1.4和Doctrine 1.2。
我在我的ProductForm.class.php中想这样的事情,但我需要一些关于如何使这项工作的输入。
感谢
class ProductForm extends BaseProductForm
{
public function configure()
{
unset($this['created_at'], $this['updated_at'], $this['id'], $this['slug']);
$this->embedRelation('ProductProperties');
}
public function saveEmbeddedForms($con = null, $forms = null)
{
if (null === $forms)
{
$properties = $this->getValue('ProductProperties');
$forms = $this->embeddedForms;
foreach($properties as $p)
{
// If property value is empty, unset from $forms['ProductProperties']
}
}
}
}
我敢肯定,它可以工作,但必须有一个更简单的解决方案,简单地排除空文件? – Rune