doujing4555 2012-05-14 16:04
浏览 26
已采纳

Zend Framework - 验证上传内容(二次验证)

I'm currently having users upload a MS Word Document where I am checking a version within the XML. The controller currently checks isValid() and then hits a library that does the parsing and extraction (since word is an archive). Now since it's technically "valid" already, I need to check the validity again through the library. What is the best course of action in Zend Framework for this?

Cheers from Kohana Land ;)

  • 写回答

1条回答 默认 最新

  • duanbi2003 2012-05-15 06:54
    关注

    I think I understand what you are looking for.
    You are currently calling is valid against the form, your file passes the form validation (correct size, extension ...) now you need to unpack the file and validate the contents.

    I'm going to assume you already have the code to validate the contents and just want to understand how that might be used in the controller.
    '

    public function anyAction() {
    
    $form = new Form();
    //test for $_POST
    if ($this->getRequest()->isPost(){
        //Test form for validity
        if ($form->isValid($this->getRequest()->getPost()){
            //will receive file upload (unless disabled in element) and filter form values,
            //based on filters attached to the elements.
            $data = $form->getValues();
            //placeholder for whatever code is required to validate contents of file
            $validateFile = new MyFileValidator();
            //test for valid file contents
            if ($validateFile->isValid($data['file']){
                //Do some Stuff 
            }
            //if file contents is not valid, display form and populate values with unfiltered values
            $form->populate($this->getRequest()->getPost());
        }
       //if form is not valid, it should stay populated and display element errors
      }
    //if not post send form to view
    $this->view->form = $form;
    }
    

    This example should provide the basic controller workflow for this type of problem. I hope it addresses your question.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路