gpt4 book ai didi

php - ZendFramework 2 表单文件验证器

转载 作者:搜寻专家 更新时间:2023-10-31 21:36:04 26 4
gpt4 key购买 nike

我一直在关注文件上传的 ZendFramework 文档: http://framework.zend.com/manual/2.1/en/modules/zend.form.file-upload.html

我的问题是,当我尝试提交无效的表单时,我收到以下错误消息:

Array provided to Escape helper, but flags do not allow recursion

这是我的 Controller 中特定操作的代码:

public function addAction()
{
$form = new TeamForm();
$form->get('submit')->setValue('Add');

$request = $this->getRequest();
if ($request->isPost()) {
$team = new Team();
$form->setInputFilter($team->getInputFilter());
$post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
$form->setData($post);

if ($form->isValid()) {
$files = $request->getFiles();
$filter = new RenameUpload(array("target" => "./public/uploads/", "use_upload_extension" => true, "randomize" => true));
$fileinfo = $filter->filter($files['image']);
$team->exchangeArray($form->getData());
$team->image = basename($fileinfo["tmp_name"]);

$this->getTeamTable()->saveTeam($team);

return $this->redirect()->toRoute('team');
}
}
return array('form' => $form);
}

我将错误缩小到以下行:

$form->setData($post);

当我对 $post 进行变量转储时,一切看起来都是正确的。在互联网上搜索后,我无法找到任何关于为什么会发生这种情况的答案。

如有必要,我很乐意提供更多相关信息。

谢谢,

编辑

这是查看代码

<?php
$form->setAttribute('action', $this->url('team', array('action' => 'add')));
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formInput($form->get('image'));
echo $this->formInput($form->get('name')
->setAttribute('class', 'large m-wrap')
->setAttribute('autocomplete', 'off')
->setAttribute('placeholder', 'Name'));
echo $this->formElementErrors($form->get('name'));
echo $this->formInput($form->get('title')
->setAttribute('class', 'large m-wrap')
->setAttribute('autocomplete', 'off')
->setAttribute('placeholder', 'Title'));
echo $this->formElementErrors($form->get('title'));
echo $this->formSubmit($form->get('submit')
->setAttribute('class', 'btn green'));
echo $this->form()->closeTag();
?>

最佳答案

问题出在你的 View 文件中,请使用

<?php echo $this->formFile($form->get('image')); ?>

代替

echo $this->formInput($form->get('image'));

文件类型应该是$this->formFile()

关于php - ZendFramework 2 表单文件验证器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19283563/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com