在zendframework中提交表单时,无法在pdf文件的编辑页面中获取pdf名称

时间:2019-02-18 07:58:39

标签: php mysql

// This is Controller 
            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()]);
                }
                 This is my model 
               public function getccDataByccCode($session,$pdId)
                {
                    $ouCode = $session->ouCode;
                    $langCode = $session->langCode;
                    $queryBuilder = $this->entityManager->createQueryBuilder();
                    $queryBuilder->select("cp.pdId,cp.pdName,cp.fileName,cp.locActive")
                            ->from(HrCompanypolicy::class, 'cp')
                            ->where('cp.ouCode = ?1')
                            ->andWhere('cp.langCode = ?2')
                            ->andWhere('cp.pdId = :pdId')
                            ->setParameter('1', $ouCode)
                            ->setParameter('2', $langCode)
                            ->setParameter('pdId', $pdId);

                    $clData = $queryBuilder->getQuery()->getResult();

                    return $clData;
                }
            This is Edit.phtml 
            <div id="page-wrapper" style="min-height: 384px;">
                <div class="row">
                    <div class="col-lg-12">
                        <h1 class="page-header"><?php //echo $label['cost_center'] ?></h1>
                        <div class="panel panel-default">
                            <div class="panel-heading">
                               <?php //echo $label['cost_center'] ?>
                            </div>
                            <?php echo $this->form()->openTag($form); ?>
                            <div class="panel-body">
                                <div class="form-group margin1">
                                    <label class="col-md-2" for="pdid"><label for="">Policy Id</label>&nbsp;&nbsp;&nbsp;<sup class="required">*</sup></label>
                                    <div class="col-md-2">

                                        <?php echo $this->formElement($form->get('pdid')); ?>
                                        <span style="color:red"><?php echo $this->formElementErrors($form->get('pdid')); ?></span> 
                                    </div>
                                    <div class="col-md-2"></div>
                                    <label class="col-md-2" for="pdname"><label for="">Policy Name</label><sup class="required">*</sup></label>
                                    <div class="col-md-3">
                                        <?php echo $this->formElement($form->get('pdname')); ?>
                                        <span style="color:red"><?php echo $this->formElementErrors($form->get('pdname')); ?></span> 
                                    </div>
                                    <div class="clearfix"></div>
                                </div>
                                 <div class="form-group margin1">
                                    <label class="col-md-2" for=""><label for="">Upload Document</label><sup class="required">*</sup></label>
                                   <div class="col-md-3">
                                                <?= $this->formElement($form->get('fileName')); ?>
                                                <span style="color:red"><?= $this->formElementErrors($form->get('fileName')); ?>
                                                <p style="color:blue;"><?php echo $clData[0]['fileName']; ?></p></span>
                                       <!--<img src="<?php //echo $target_file['fileName']['name'];?>" />-->
                                           <!--<img src="<?php //echo 'public/media/policy_photos/' . $photoUrl; ?>" width="50px">-->
                                            </div>
                                    <div class="clearfix"></div>
                                </div>
                                  <div class="form-group margin1">
                                    <label class="col-md-2" for="active"><?php echo $label['active']; ?></label>
                                    <div class="col-md-10">
                                        <div class="checkbox">
                                            <label>
                                                <?php echo $this->formElement($form->get('active')); ?>
                                            </label>
                                        </div>
                                    </div>
                                    <div class="clearfix"></div>
                                </div>
                              <?php echo $this->formElement($form->get('Submit')); ?>
                            </div>
                            <?php echo $this->form()->closeTag($form); ?>

                        </div>

                    </div>
                    <!-- /.col-lg-12 -->
                </div>
                <!-- /.row -->

                <!-- /.row -->
                <div class="row">

                </div>
                <!-- /.row -->
            </div>

在Controller中,我在此处接收文件名的编辑功能

$pdId = $this->params()->fromRoute('id');
         if (!empty($pdId)) {
                $clData = $this->companyPolicyManager->getccDataByccCode($this->sessionContainer, $pdId);
    $companyPolicyForm->setData($clData[0]);
    echo '<pre>90909';
        print_r($clData);
                    exit;
        $companyPolicyForm->buildCompanyPolicyData($clData);
                }
        output is :
        90909Array
        (
            [0] => Array
                (
                    [pdId] => 101
                    [pdName] => holidays_list
                    [fileName] => lesson2.pdf
                    [locActive] => 1
                )

        )
        but when i submit the this data using this code ie posting the data i m getting an empty array like this Array() 
        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;
         output: Array()

为什么我要获取数据?     在这里,我正在编辑表单policyid,policyname,policy文件上载,而问题在于政策文件上载。 我有三个字段策略ID,策略名称,策略文件名。 我现在正在编辑,但是当我提交表单而不编辑三个字段中的任何一个时,它应该成功提交。

如果需要更多文件,我将提供。 。此处文件已在编辑页面中上传,只需提交所有三个字段即可,无需进行任何编辑。 在这里,我正在使用zendframework 3和“查询”构建器。

代码中的问题是什么? 我该如何解决?  在这里,我正在使用zendframework 3和“查询”构建器。

0 个答案:

没有答案