【问题标题】:Zend Form : Call to undefined method Zend\InputFilter\InputFilter::getFilterChain()Zend Form:调用未定义的方法 Zend\InputFilter\InputFilter::getFilterChain()
【发布时间】:2016-10-05 12:58:58
【问题描述】:

我正在尝试使用 Zend Form 上传图像。由于我们需要它来移动图像,我想添加一个过滤器来完成这项工作。但我不能使用 getInputFilterChain(),我一直有这个致命错误:Call to undefined method Zend\InputFilter\InputFilter::getFilterChain()。我在这里想念什么?

我能够在 $prg 数组中获取文件信息。而正如我在https://framework.zend.com/manual/2.4/en/modules/zend.mvc.plugins.html 上看到的,这种方法应该存在于这里,不是吗?

如果我在我的 Form.php 文件中使用它,我会得到同样的错误。

提前感谢您的宝贵时间!

我的控制器动作:

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
    ...
}

【问题讨论】:

    标签: php zend-framework zend-form


    【解决方案1】:

    您需要先从InputFilter 中获取Input 实例,然后才能从输入中获取过滤器链:

    $inputName = 'file'; // name of the input you want to work with
    $input = $form->getInputFilter()->get($inputName);
    $filterChain = $input->getFilterChain();
    

    【讨论】:

    • 哈这看起来非常非常非常合乎逻辑。再次感谢您的宝贵时间!
    猜你喜欢
    • 1970-01-01
    • 2013-01-30
    • 1970-01-01
    • 1970-01-01
    • 2015-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多