【发布时间】:2011-04-28 10:06:04
【问题描述】:
必须是一些简单的解决方法,但作为一个初学者,我已经花了 2 天时间试图找出答案。我有一个简单的表单(“enctype =“multipart/form-data”),文本和文件的输入很少。我不知道出了什么问题,我可以通过 getParameter() 获取用户的文本数据,但无法获取文件getFiles()。我在 ubuntu 11.04 php5.3
代码:
表单类:
public function configure()
{
$this->setWidgets(array(
'vendor' => new sfWidgetFormInputText(array(), array('class' => 'form-text')),
'image' => new sfWidgetFormInputFile(array(), array('class' => 'form-text')),
'city' => new sfWidgetFormInputText(),
'email' => new sfWidgetFormInputText(array('default' => 'simple@sample.org')),
'contacts' => new sfWidgetFormTextarea(),
'description' => new sfWidgetFormTextarea(),
));
$this->setValidators(array(
'vendor' => new sfValidatorString(array('required' => false)),
'image' => new sfValidatorFile(array(
'required' => false,
'path' => sfConfig::get('sf_upload_dir') . '/images',
'mime_types' => 'web_images')),
'city' => new sfValidatorString(array('required' => false)),
'email' => new sfValidatorString(array('required' => false)),
'contacts' => new sfValidatorString(array('required' => false)),
'description' => new sfValidatorString(array('required' => false)),
));
$this->widgetSchema->setNameFormat('pv[%s]');
}
行动:
public function executeCreate(sfWebRequest $request)
{
$this->forward404Unless($request->isMethod(sfRequest::POST));
return $this->renderText(var_dump($request->getParameter('pv'))); //this array include vars from form
//return $this->renderText(var_dump($request->getFiles('pv'))); //empty array
}
【问题讨论】:
-
好的,我明白了我的问题,我使用的是 jq 插件,提交按钮是 jq_submit_to_remote(),这不是我应该做的。
标签: symfony1 symfony-1.4