问题
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 ?
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 ?
And I get the same error if I use this in my Form.php file.
Thank you in advance for your time!
My controller action :
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
...
}
回答1:
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();
来源:https://stackoverflow.com/questions/39874645/zend-form-call-to-undefined-method-zend-inputfilter-inputfiltergetfilterchai