I am making a form that consists of some text and file uploads. The problem is that the file was not saved in the db (blob) field because the client did not want to, so I did UploadFileForm to clear it and execute the loading and saving logic in the file table (which has a path to this file). So, I have a:
class HistoryForm extends BaseHistoryForm
{
public function configure()
{
unset($this['text']);
$this->setWidget('text', new sfWidgetFormTextareaTinyMCE(array(
'width' => 550,
'height' => 350,
'config' => 'theme_advanced_disable: "anchor,image,cleanup,help"',)));
$this->setValidator('text', new sfValidatorString());
$this->embedForm('uploadfile1', new UploadFileForm());
}
}
class UploadFileForm extends sfForm{
public function configure() {
$this->setWidget('file', new sfWidgetFormInputFile());
$this->setValidator('file', new sfValidatorFile(array(
'required' => false,
'path' => sfConfig::get('sf_upload_dir')
)));
$this->setWidget('name', new sfWidgetFormInputText());
$this->setValidator('name', new sfValidatorString(array('required' => true)));
$this->widgetSchema->setNameFormat('uploadfile[%s]');
}
public function save({data_to_be_saved}){
}
}
, , , (, , sfForms ), saveEmbeddedForms sfForm ! symfony , , , widgetSchema, ... , , sfForm, , . :
class HistoryForm extends BaseHistoryForm
{
...
public function save($con = null) {
$hc = parent::save($con);
foreach ($this->getEmbeddedForms() as $form) {
$values = $this->getValue($form->getName());
$form->save($hc, $values);
}
}
symfony . ... - ( ) ?