在phalconPHP中呈现DOMPDF的视图

时间:2017-07-24 07:59:47

标签: angularjs phalcon dompdf

我一直试图在phalconPHP中使用DOMJDF将模板转换为PDF,前面是angularJS。但我从它得到500内部服务器错误响应。 DOMPDF包含在控制器中,因为我在load_html()函数中加载了静态HTML,它运行正常。以下是ReportsController的报告操作。不要打扰整个代码,只是跳到最后的DOMPDF相关代码。 $ patients是包含模板所需的所有数据的数组。

ReportController的reportAction:

    public function reportAction()
{
    $patientsModel = new Patients();
    $patients = array();
    $patients['data'] = array();

    $tmpfilters = $this->queryfilters;
    unset($tmpfilters['limit']);

    $tmpfilters2 = array();
    $tmpfilters2['models'] = "PRM\\Models\\Patients";
    if( isset( $tmpfilters['conditions'] ) )
    {
        $tmpCondition = preg_replace("/[^0-9]/", '', $tmpfilters['conditions']);
        $tmpfilters2['conditions'] = "clinic = " . $tmpCondition . " AND status = 24";
    }
    else
    {
        $tmpfilters2['conditions'] = "status = 24";
    }
    $tmpActivePatients = new Patients();
    $tmpActivePatients = $tmpActivePatients->find($tmpfilters2);
    $patients['activeTotal'] = $tmpActivePatients->count();

    $tmpfilters3 = array();
    $tmpfilters3['models']['m'] = "PRM\\Models\\Activity";
    $tmpfilters3['models']['s'] = "PRM\\Models\\Patients";
    if( isset( $tmpfilters['conditions'] ) )
    {
        $tmpCondition2 = preg_replace("/[^0-9]/", '', $tmpfilters['conditions']);
        $tmpfilters3['conditions'] = "m.clinic = " . $tmpCondition2 . " AND " . "s.clinic = " . $tmpCondition2 . " AND m.patient=s.id AND m.duration > 1";
    }
    else
    {
        $tmpfilters3['conditions'] = "m.patient = s.id AND m.duration > 1";
    }
    $tmpPatientDuration = new Query($tmpfilters3);
    $tmpPatientDuration = $tmpPatientDuration->getQuery()->execute();
    //$builder = $this->modelsManager->createBuilder();
    $patients['billableTotal'] = $tmpPatientDuration->count();
    //$builder->addFrom('PRM\\Models\\Activity', 'a')->innerJoin('PRM\\Models\\Patients', 'p.id=a.patient', 'p')->where('a.duration > 1 AND p.status = 24');
    //$result = $builder->getQuery()->execute();
    //$patients['billableTotal'] = $result->count();

    foreach ($tmpPatientDuration as $patient) {
        array_push($patients['data'], array(
            'id' => $patient->id,
            'firstname' => $patient->s->firstname,
            'lastname' => $patient->s->lastname,
            'duration' => $patient->m->duration,
            'billingCode' => "CPT 99490"));
            /*'icd1' => Ccm::findFirstById($patient->icd1)->icdcode,
            //'icd2' => Ccm::findFirstById($patient->icd2)->icdcode,
            //'clinic' => Clinics::findFirstById($patient->clinic)->name,
            'duration' => Activity::sum([
                "column" => "duration",
                "conditions" => "patient = '{$patient->id}'",
            ]),
            'response' => Activity::findFirst([
                "conditions" => "patient = '{$patient->id}' and activity='Communication' ",
                "order" => "id desc"
            ])->description,
            'status' => Status::findFirstById($patient->status)->name));*/
    }


    $html = $this->view->getRender("reports", "report", $patients);
    $dompdf = new domPdf();
    $dompdf->load_html($html);
    $dompdf->setPaper('A4', 'landscape');
    $dompdf->render();


    //$this->response->setJsonContent($patients);
    $this->response->setContentType('application/pdf');
    $this->response->setContent($dompdf->stream());
    $this->response->send();
}

这是angularJS控制器的代码:

    $http.get('common/reports/report', {responseType: 'arraybuffer'}).success(
        function (data) {
            var file = new Blob([data], {type: 'application/pdf'});
            var fileURL = URL.createObjectURL(file);
            window.open(fileURL);
        }).error(
        function (data) {
            angular.forEach(data, function (error) {
                $scope.error[error.field] = error.message;
                console.log(error.field);
            });
            $alert({title: 'Error!', content: data.flash.message, placement: 'top-right', type: data.flash.class , duration: 10, container: '.site-alert'});
        }
    );

错误日志: error log for the above problem

0 个答案:

没有答案