3

我一直在关注 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

这是我的控制器中特定操作的代码:

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();
?>
4

3 回答 3

2

问题出在您的视图文件中,请使用

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

代替

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

对于文件类型,它应该是$this->formFile()

于 2014-04-02T05:28:48.297 回答
0

问题不在于控制器,而在于视图。您正在将数组escape()而不是字符串传递给视图助手。

于 2013-10-14T13:08:31.780 回答
-1

我认为问题出在上面的那一行,做一个 array_merge 而不是递归合并。

于 2013-10-11T20:05:23.023 回答