mergeForm() - symfony
I'm using mergeForm to display a form and then another merged into it.
The form I'm editting is the admin module for Article with a ContentItemForm merged.
Schema in simple terms is:
Article
id
ContentItem
id
article_id
is_comment
In my ArticleForm I have the following:
public function configure()
{
$this->mergeForm(new ContentItemForm(ContentItemPeer::retrieveB开发者_运维问答yPK($this->getObject()->getId())));
}
public function save($con = null)
{
parent::save();
$this->updateContentItem();
return $this->object;
}
protected function updateContentItem()
{
// update content item
if (!is_null($article_content = $this->getContentItem()))
{
$values = $this->getValues();
if ( $article_content->isNew() )
{
$values['article_id'] = $this->object->getId();
}
$article_content->fromArray($values, BasePeer::TYPE_FIELDNAME);
$article_content->save();
}
}
protected function getContentItem()
{
if (!$this->object->getContentItem())
{
return new ContentItem();
}
else
{
return $this->object->getContentItem();
}
}
In the admin, this merges the form and i see the contentItemForm and it's fields. is_comment is a boolean value and therefore displays a checkbox. When I have it checked, it is suppoed to update the is_comment field in the content_item table to 1, unchecked and saved, should be 0.
Unfortunately, this isn't working. The is_comment field is never updated.
Does anyone know what could be causing this?
Have you set a relation between Article and ContentItem? Then you shouldn't have to do anything specific in the save() method.
精彩评论