2016-12-27 3 views
0

私はPHPアプリケーションでジャスパーレポートを生成しようとしています。私はSymfony2を研究しています。実際に私のアプリケーションで私のレポートを生成するが、問題はIreportで、私は私のPHPアプリケーションから送信するPHP変数を取得していない。そして私の報告はJasperserverにあります。IreportでPHP変数を取得する方法

これは私のPHPアプリケーションから自分の行動である:私は明らかだ願ってい

<?xml version="1.0" encoding="UTF-8"?> 
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="RechercheGoogle" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="7e1de1d9-a08e-47ec-8af2-e93dbec288e7"> 
    <property name="ireport.zoom" value="1.0"/> 
    <property name="ireport.x" value="0"/> 
    <property name="ireport.y" value="0"/> 
    <parameter name="id_pef" class="java.lang.Integer"/> 
    <background> 
     <band splitType="Stretch"/> 
    </background> 
    <title> 
     <band height="270" splitType="Stretch"> 
      <staticText> 
       <reportElement x="82" y="34" width="100" height="20" uuid="8969389a-851b-44e5-a88c-14a4b217fc47"/> 
       <text><![CDATA[Coucou !!!]]></text> 
      </staticText> 
      <staticText> 
       <reportElement x="252" y="21" width="240" height="58" uuid="1bebe360-cabf-485f-a158-befade8ee7a9"/> 
       <textElement> 
        <font size="14"/> 
       </textElement> 
       <text><![CDATA[ID du PEF: $P{id_pef}]]></text> 
      </staticText> 
      <textField> 
       <reportElement x="322" y="125" width="100" height="20" uuid="eae36fce-573e-484c-8cca-e8b4007d5e2b"/> 
       <textFieldExpression><![CDATA[$P{id_pef}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="224" y="109" width="100" height="20" uuid="2e2db24f-899b-45d0-9434-62cdd0f35171"/> 
       <textFieldExpression><![CDATA[$P{id_pef}]]></textFieldExpression> 
      </textField> 
     </band> 
    </title> 
    <pageHeader> 
     <band height="35" splitType="Stretch"/> 
    </pageHeader> 
    <columnHeader> 
     <band height="61" splitType="Stretch"/> 
    </columnHeader> 
    <detail> 
     <band height="125" splitType="Stretch"/> 
    </detail> 
    <columnFooter> 
     <band height="45" splitType="Stretch"/> 
    </columnFooter> 
    <pageFooter> 
     <band height="54" splitType="Stretch"/> 
    </pageFooter> 
    <summary> 
     <band height="42" splitType="Stretch"> 
      <textField> 
       <reportElement x="432" y="22" width="100" height="20" uuid="0d41b36b-f441-400c-af62-753fa3cb4b63"/> 
       <textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression> 
      </textField> 
     </band> 
    </summary> 
</jasperReport> 

public function result_recherche_googleAction(){ 

    $em = $this->getDoctrine()->getManager(); 

    $request = $this->getRequest(); 
    $id_pef = $request->request->get('id_pef'); 

    if ($request->isXmlHttpRequest()) { 


     $jasperclient=new JasperClient(); 
     $lien=$jasperclient->getUrlManyParams($this->container,"RechercheGoogle",array("id_pef" => $id_pef));  


     return $this->get('templating')->renderResponse('gideBundle:Edition:res_edition_recherche_google.html.twig',array(
     //'trans'=>$pefs, 
     'lien'=>$lien, 
     )); 
    //} 
    } 
    else { 
     //return $this->feuillePEFAction(); 
     return new Response(json_encode($id_pef)); 
    } 
} 

は、これは私のレポートからのコードです。私はすべてを試して、私は多くのことを検索しますが、私の問題に関する情報はすべて探します。私は誰かが私を助けてくれることを願っています。私の問題についての詳細な情報が必要な場合は教えてください。

EDIT:

この私がjasperserverでリンクを作成するためにsymfonyのparameter.ymlに入れる:

jasper: 
hostname: localhost 
tcpport: '8080' 
parentfolder: reports/nightly 
username: username 
userpass: mdp 
specialparams: '_flowId=viewReportFlow&standAlone=true&_datasource=nightlydatasource' 

私のPHPのvariablre上のvar_dumpで "*先取特権" 私はこのURLを持っています:

string 'http://localhost:8080/jasperserver/flow.html?_flowId=viewReportFlow&standAlone=true&_datasource=nightlydatasource&ParentFolderUri=reports/nightly&j_username=username&j_password=mdp&reportUnit=%2freports/nightly%2fRechercheGoogle&id_pef=104039-01-01' (length=269) 

私は自分の見解でレポートを呼び出します。レポートは正しくコールされていますが、レポートにphp変数がありません。

答えて

0

指定されたjrxmlドキュメントからPDFレポートを生成するPHPライブラリ(サードパーティ製)が必要です。このライブラリは、次のGitリポジトリからダウンロードできます。 https://github.com/chathurangat/PhpJasperLibrary

すべての設計が完了したら、今度はPHPアプリケーションと統合することになります。 PHPスクリプトでPhpJasperLibraryをダウンロードしてインポートしてください。あなたのLAMP/WAMPサーバに

<?php 

//Import the PhpJasperLibrary 
include_once('PhpJasperLibrary/tcpdf/tcpdf.php'); 
include_once("PhpJasperLibrary/PHPJasperXML.inc.php"); 


//database connection details 

$server="192.168.0.11"; 
$db="lcs_ims"; 
$user="web"; 
$pass="[email protected]#"; 
$version="0.8b"; 
$pgport=5432; 
$pchartfolder="./class/pchart2"; 


//display errors should be off in the php.ini file 
ini_set('display_errors', 0); 

//setting the path to the created jrxml file 
$xml = simplexml_load_file("report/chathuReport.jrxml"); 

$PHPJasperXML = new PHPJasperXML(); 
//$PHPJasperXML->debugsql=true; 
//$PHPJasperXML->arrayParameter=array("parameter1"=>1); 
$PHPJasperXML->xml_dismantle($xml); 

$PHPJasperXML->transferDBtoArray($server,$user,$pass,$db); 
$PHPJasperXML->outpage("I"); //page output method I:standard output D:Download file 


?> 

アクセスreport_view.phpファイルを(同じディレクトリに.jasperと.jrxmlファイルの両方をコピーして、PHPスクリプト内の参照を与えます)。よろしくお願いします。

check link for more details

、あなたは動的な値を取得したい場合は、その後sql functionを使用しています。


私のアプリケーションでは、私はJaperレポートを呼び出し、パラメータ以外は正しく表示されるため、私のドキュメントをうまく生成しています。 symfonyにおいて

私はこのようなジャスパーに接続する私を可能にするものparameter.ymlに追加:

jasper: 
    hostname: localhost 
    tcpport: '8080' 
    parentfolder: reports/nightly 
    username: username 
    userpass: mdp 
    specialparams: '_flowId=viewReportFlow&standAlone=true&_datasource=nightlydatasource' 

ティエン私はあなたが私に尋ねたURLを持っています。私はこのような私のコントローラのアクションから私のリンク変数ののvar_dumpを行うことによってそれを得た:私は、これは碧玉サーバー上で実行されると思います

string 'http://localhost:8080/jasperserver/flow.html?_flowId=viewReportFlow&standAlone=true&_datasource=nightlydatasource&ParentFolderUri=reports/nightly&j_username=username&j_password=mdp&reportUnit=%2freports/nightly%2fRechercheGoogle&id_pef=104039-01-01' (length=269) 

:ここ

$jasperclient=new JasperClient(); 
      $lien=$jasperclient->getUrlManyParams($this->container,"RechercheGoogle",array("id_pef" => $id_pef)); 
      var_dump($lien); exit; 

は、URLです。

<div> 
    <div class="rech_form" style="width: 664px; height:100px; " > 
     <input id="input_rech" 
       style="text-transform:uppercase; width: 512px; float: left; height: 32px; border-radius: 0; border: none; 
         background: url({{ asset('bundles/gide/images/input_rech.jpg') }}) ; 
         color: #92a4b0; font-family: 'Myriad Pro', Helvetica, Arial, sans-serif; font-size: 14px;" 
         placeholder="Enter an EFP, TJ, Location ..." /> 

     <input type="button" value="{{ 'Recherche' }}" id="bt_recherche_google" onclick='recherche_google("{{ugpef}}")' /> 
     <!-- <button id="bt_rech">Research</button>--> 
     <br /> 
     <div id="bloc_gauche" style="float:left;width:33%;"> 
      <input type="checkbox" id="choix_armoire" class="k-checkbox" /> 
      <label for="choix_armoire" class="k-checkbox-label"> Name Wardrobe </label> 
      <br /><br /> 
      <input type="checkbox" id="choix_code_mire" class="k-checkbox" /> 
      <label for="choix_code_mire" class="k-checkbox-label"> Code Mire </label> 
     </div> 
     <div id="bloc_milieu" style="float:left;width:33%;margin-left:auto;"> 
      <input type="checkbox" id="choix_code_GMAO" class="k-checkbox" /> 
      <label for="choix_code_gmao" class="k-checkbox-label"> Code GMAO </label> 
      <br /><br />  
      <input type="checkbox" id="choix_repere_depart" class="k-checkbox" /> 
      <label for="choix_repere_depart" class="k-checkbox-label"> Repère de Départ </label> 
     </div> 
     <div id="bloc droit" style="float:left;width:33%;margin-left:auto;">   
      <input type="checkbox" id="choix_libelle_appareil" class="k-checkbox" /> 
      <label for="choix_libelle_appareil" class="k-checkbox-label"> Device Label </label> 
      <br /><br />  
      <input type="checkbox" id="choix_observation" class="k-checkbox" /> 
      <label for="choix_observation" class="k-checkbox-label"> Observation </label> 
     </div> 

    </div> 
     <!--<button class="buttonPro orange" id="bouton_close" onclick="closewindow();" type="button">Cancel</button>--> 
    <div id="rapport_recherche_google"> </div> 
</div>   
<script> 
    /* var pef="{{ugpef}}"; 


$(document).ready(function() { 


    $('#bt_recherche_google').click(function() { 
       alert(pef); 
      }); 
});*/ 
function recherche_google(id_pef){ 
    alert(id_pef); 

    $.ajax({ 
     type: 'POST', 
     url : "{{ path('result_recherche_google')}}", 
     dataType : 'text', 
     data : { 
      id_pef: id_pef // We give the typed string in the search field 
        }, 
     success : function(data){ // We prepare to return the data received thanks to the event of success 
      console.log(data); 
      $('#rapport_recherche_google').html(data); 
     }, 
     error : function(erreur){ 
      alert("An error has occurred "+ erreur); 
      console.log(erreur); 
     } 
    }); 
    } 
</script> 

あなたは、私が「見ることができるとして:それはそれの世話をすると、私はここで忘れてしまったjasperserverあるレポートの管理は私がレポートを投稿する図であり、後にアプリケーションがちょうどWAMPサーバの下で使用されているので、 (私の最初のメッセージで与えられたコード)を入力すると、この呼び出しはdivに組み込まれます。これはjasperレポートを実際に表示します:

<div style="width:100%;height: 780px;position:relative"> 
<div id="hider" style="background: url('/web/bundles/gide/images/banner_bkgd.png') repeat-x scroll 0 0 #2881BB;;display:block;position:absolute;top:2px;left:0;height: 26px; width: 100%;z-index: 10;"></div> 
<iframe name="zone" id="zone" src="{{lien}}" style=" height: 700px;width: 100%;position:absolute;left:0;top:0;"></iframe > 
</div> 

ここでは、自己ではない場合、適切な情報を提供したいと考えています。

+0

ありがとうございます。しかし、私はJasperClientを使用します。これはJasperのPHPクラスです: – Arendelle

+0

私は上記のライブラリを使っていますが、あなたの既存のライブラリを変更することはできませんでしたが、SQL関数を使用して値thrを渡すことはできませんでした –

+0

申し訳ありません、このアプリケーションは他の誰かによって開発されたので、今はそれが私のものです。だからあなたはライブラリJasperClientを使用しましたか?そして私はそれをどのように価値thrに​​渡すことができますか? – Arendelle

0

JasperReports Serverの私のレポートでは、iReportの「入力コントロール」を追加するだけです。

見て、これはiReportはからJRサーバー(uouがJRサーバーiReportは中で接続する必要がある)との図である。

jasperserver view from ireport

私はこのビューでは、私のレポートを検索し、私が追加した後そして、このようなディレクトリ「入力コントロール」での入力コントロール:

My report with input control

私はちょうど右のCLを行いますick in "Input Control"をクリックし、 "Create a local input control"をクリックして、iReportからの私のパラメータのような入力コントロールの名前をつけた後に動作します。

今、私はphp変数を送ることができ、私はこの変数をレポートに入れます。

関連する問題