Zend Form : Call to undefined method Zend\InputFilter\InputFilter::getFilterChain()

点点圈 提交于 2019-12-12 02:45:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!