我正在使用 Symfony 1.4.4 和 Doctrine,我需要在服务器上上传一张图片。
我已经这样做了数百次而没有任何问题,但这次发生了一些奇怪的事情:我没有将文件名存储在数据库中,而是找到了字符串“Array”。
这就是我正在做的事情:
在我的表格中:
$this->useFields(array('filename'));
$this->embedI18n(sfConfig::get('app_cultures'));
$this->widgetSchema['filename'] = new sfWidgetFormInputFileEditable(array(
'file_src' => '/uploads/flash/'.$this->getObject()->getFilename(),
'is_image' => true,
'edit_mode' => !$this->isNew(),
'template' => '<div id="">%file%</div><div id=""><h3 class="">change picture</h3>%input%</div>',
));
$this->setValidator['filename'] = new sfValidatorFile(array(
'mime_types' => 'web_images',
'path' => sfConfig::get('sf_upload_dir').'/flash',
));
在我的行动中:
public function executeIndex( sfWebRequest $request )
{
$this->flashContents = $this->page->getFlashContents();
$flash = new FlashContent();
$this->flashForm = new FlashContentForm($flash);
$this->processFlashContentForm($request, $this->flashForm);
}
protected function processFlashContentForm($request, $form)
{
if ( $form->isSubmitted( $request ) ) {
$form->bind( $request->getParameter( $form->getName() ), $request->getFiles( $form->getName() ) );
if ( $form->isValid() ) {
$form->save();
$this->getUser()->setFlash( 'notice', $form->isNew() ? 'Added.' : 'Updated.' );
$this->redirect( '@home' );
}
}
}
在绑定我的参数之前,一切都很好,$request->getFiles($form->getName())
返回我的文件。但之后,$form->getValue('filename')
返回字符串“Array”。
你们中的任何人都发生过这种情况吗,或者您发现我的代码有什么问题吗?
编辑:我添加了一个事实,即我正在嵌入另一个表单,这可能是问题所在(请参阅上面的表单代码)。