如何从zendframework 3中的表单中获取帖子数据

时间:2019-02-18 10:17:25

标签: php mysql

public function editAction()
{
   if ($this->sessionContainer->empId == "") {
      return $this->redirect()->toRoute('admin_user_login');
   }
   $ouCode = $this->sessionContainer->ouCode;
   $langCode = $this->sessionContainer->langCode;
   $empId = $this->sessionContainer->empId;
   $arrLabel = array('company_policy', 'pdid', 'pdname', 'fileName','active');
   $commonTransalationLabel = $this->commonTranslation->getCommonTransactionInformation($arrLabel, $langCode);
   $companyPolicyForm = new companyPolicyForm($commonTransalationLabel);
   $pdId = $this->params()->fromRoute('id');
   if (!empty($pdId)) {
      $clData = $this->companyPolicyManager->getccDataByccCode($this->sessionContainer, $pdId);
      $companyPolicyForm->setData($clData[0]);
      $companyPolicyForm->buildCompanyPolicyData($clData);
   }
   if ($this->getRequest()->isPost()) {
      $request = $this->getRequest();
      $data = array_merge_recursive(
      $request->getPost()->toArray(), $request->getFiles()->toArray()
      );
      $data['ouCode'] = $ouCode;
      $data['langCode'] = $langCode;
      $companyPolicyForm->setData($data);
      if ($companyPolicyForm->isValid()) 
      {
         public function editAction()
         {
             if ($this->sessionContainer->empId == "") {
                return $this->redirect()->toRoute('admin_user_login');
             }
             $ouCode = $this->sessionContainer->ouCode;
             $langCode = $this->sessionContainer->langCode;
             $empId = $this->sessionContainer->empId;
             $arrLabel = array('company_policy', 'pdid', 'pdname', 'fileName','active');
             $commonTransalationLabel = $this->commonTranslation->getCommonTransactionInformation($arrLabel, $langCode);
             $companyPolicyForm = new companyPolicyForm($commonTransalationLabel);
             $pdId = $this->params()->fromRoute('id');
             if (!empty($pdId)) {
                $clData = $this->companyPolicyManager->getccDataByccCode($this->sessionContainer, $pdId);
                $companyPolicyForm->setData($clData[0]);
                $companyPolicyForm->buildCompanyPolicyData($clData);
             }
             if ($this->getRequest()->isPost()) {
                $request = $this->getRequest();
                $data = array_merge_recursive(
                $request->getPost()->toArray(), $request->getFiles()->toArray()
                );
                $data['ouCode'] = $ouCode;
                $data['langCode'] = $langCode;
                $companyPolicyForm->setData($data);
                if ($companyPolicyForm->isValid()) 
                {
                    $this->companyPolicyManager->updateCompanyPolicy($data,$ouCode,$langCode,$empId);
                    $this->flashMessenger()->addMessage('Added successfully');
                    return $this->redirect()->toRoute('wfm_job_company_policy_manage');
                    } else {
                            if(empty($clData))
                            {
                               $form->setData($clData[0]);
                            }
                            if (!empty($clData)) {
                               $companyPolicyForm->setData($clData[0]);
                            }

                       }
                  }
                  return new ViewModel(['form' => $companyPolicyForm,
                  'label' => $commonTransalationLabel,
                  'clData' => $clData,
                  'flashMessages' => $this->flashMessenger()->getMessages()]);
             }
             $name = $_FILES['fileName']['name'];
             $target_dir = 'public/media/policy_photos/';
             $target_file = $target_dir . basename($_FILES["fileName"]["name"]);
             $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
             $extensions_arr = array('pdf');
             if( in_array($imageFileType,$extensions_arr) )
             {
                move_uploaded_file($_FILES['fileName']['tmp_name'],$target_dir.$name);
             }
             }
                if(isset($_FILES['fileName']))
                 {
                    $errors     = array();
                    $maxsize    = 3097152;
                    $acceptable = array(
                        'pdf'
                    );
                if(($_FILES['fileName']['size'] >= $maxsize) || ($_FILES["fileName"]["size"] == 0)) 
                {

                        $value1 = 'File too large. File must be less than 2 megabytes';
                    }
                if(!empty($_FILES['fileName']['name']))
                {
                  $value2 = 'File is not uploaded';
                }
                if((!in_array($_FILES['fileName']['type'], $acceptable)) && (!empty($_FILES["fileName"]["type"])))
                 {
                        $value3 = 'Invalid file type. Only PDF  types are accepted';
                }
                if(!isset($_FILES['fileName']) || $_FILES['fileName']['name'] == UPLOAD_ERR_NO_FILE) {
                    $value4 =  'Error no file selected'; 
                } 
                if(count($errors) === 0) 
                {

                   move_uploaded_file($_FILES['fileName']['tmpname'],$target_file);
                }

                }
                                 //$data = $companyPolicyForm->getData();
                                $this->companyPolicyManager->updateCompanyPolicy($data,$ouCode,$langCode,$empId);
                                $this->flashMessenger()->addMessage('Added successfully');
                               return $this->redirect()->toRoute('wfm_job_company_policy_manage');

                            } else {
                                if(empty($clData))
                                {
                                $form->setData($clData[0]);
                               }
                                if (!empty($clData)) {

                                $companyPolicyForm->setData($clData[0]);
                              }

                            }
                        }
                     return new ViewModel(['form' => $companyPolicyForm,
                         'label' => $commonTransalationLabel,
                         'clData' => $clData,
                          'flashMessages' => $this->flashMessenger()->getMessages()]);
                    }

                   i want to fetch the pdf file name but in this logic i m not able to fetch the pdf file name which is uploaded.the error occur during the posting the data.
          if ($this->getRequest()->isPost()) {

                    $request = $this->getRequest();



                    $data = array_merge_recursive(
                            $request->getPost()->toArray(), $request->getFiles()->toArray()
                    );

                    $data['ouCode'] = $ouCode;
                    $data['langCode'] = $langCode;
        echo '<pre>';
        print_r($data);
        die;
        i m getting empty array 
    AND 
    here i m getting the data 
     if (!empty($pdId)) {
                $clData = $this->companyPolicyManager->getccDataByccCode($this->sessionContainer, $pdId);
    echo '<pre>';
    print_r(clData);
    die;

               $companyPolicyForm->setData($clData[0]);


                $companyPolicyForm->buildCompanyPolicyData($clData);
            }

代码中的问题是如何解决的?需要任何其他文件将有所帮助。解决方法是什么?帮我解决

Zend框架3中的数据,代码中的问题是什么,如何解决错误?

0 个答案:

没有答案