Zend 表单:调用未定义的方法 Zend\InputFilter\InputFilter::getFilterChain() [英] Zend Form : Call to undefined method Zend\InputFilter\InputFilter::getFilterChain()
问题描述
我正在尝试使用 Zend Form 上传图像.因为我们需要它来移动图像,所以我想添加一个过滤器来完成这项工作.但是我不能使用 getInputFilterChain(),我一直有这个致命错误:Call to undefined method Zend\InputFilter\InputFilter::getFilterChain()
.我在这里错过了什么?
I'm trying to upload an image with Zend Form. As we need it to move the image, I want to add a filter to do the job. But I can't use the getInputFilterChain(), I keep having this fatal error : Call to undefined method Zend\InputFilter\InputFilter::getFilterChain()
. What am I missing here ?
我能够在 $prg 数组中获取文件信息.当我查看 https://framework.zend 时.com/manual/2.4/en/modules/zend.mvc.plugins.html,这里应该有这个方法,不是吗?
I'm able to get the file information in $prg array. And as I looked on https://framework.zend.com/manual/2.4/en/modules/zend.mvc.plugins.html, this method is supposed to exist here, no ?
如果我在我的 Form.php 文件中使用它,我会得到同样的错误.
And I get the same error if I use this in my Form.php file.
提前感谢您的时间!
我的控制器操作:
public function signinAction()
{
$this->em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
$form = new SignupForm($this->em);
$form->getInputFilter()->getFilterChain()->attach(
new Zend\Filter\File\RenameUpload(array(
'target' => './data/tmpuploads/file',
'randomize' => true,
))
);
$model = new ViewModel(array("form" => $form));
$url = $this->url()->fromRoute("signin");
$prg = $this->fileprg($form, $url, true);
if($prg instanceof \Zend\Http\PhpEnvironment\Response){
return $prg;
}
else if($prg === false){
return $model;
}
//other stuff
...
}
推荐答案
您需要先从 InputFilter
中获取 Input
实例,然后才能获取过滤器-来自输入的链:
You need to get the Input
instance from the InputFilter
first and then you can get the filter-chain from the input:
$inputName = 'file'; // name of the input you want to work with
$input = $form->getInputFilter()->get($inputName);
$filterChain = $input->getFilterChain();
这篇关于Zend 表单:调用未定义的方法 Zend\InputFilter\InputFilter::getFilterChain()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!