| <?php |
| |
| Header("Location: /birt/documentation/integrating/using-php.php"); require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/app.class.php"); require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/nav.class.php"); require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/menu.class.php"); $App = new App(); $Nav = new Nav(); $Menu = new Menu(); include($App->getProjectCommon()); # All on the same line to unclutter the user's desktop' |
| |
| # |
| # Begin: page-specific settings. Change these. |
| $pageTitle = "Integrating BIRT with PHP"; |
| $pageKeywords = ""; |
| $pageAuthor = ""; |
| |
| # Add page-specific Nav bars here |
| # Format is Link text, link URL (can be http://www.someothersite.com/), target (_self, _blank), level (1, 2 or 3) |
| # $Nav->addNavSeparator("My Page Links", "downloads.php"); |
| # $Nav->addCustomNav("My Link", "mypage.php", "_self", 3); |
| # $Nav->addCustomNav("Google", "http://www.google.com/", "_blank", 3); |
| |
| # End: page-specific settings |
| # |
| |
| require "../birt.inc"; |
| require "deploy.inc"; |
| $currentPage = "Using PHP"; |
| $linkToTop = linkToTop(); |
| $deployLinksSideItem = getDeployLinksSideItem($currentPage); |
| |
| |
| # Paste your HTML content between the EOHTML markers! |
| $html = <<<EOHTML |
| |
| <!-- Google Tag Manager --> |
| <noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-PW8LFV" |
| height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> |
| <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': |
| new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], |
| j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= |
| '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); |
| })(window,document,'script','dataLayer','GTM-PW8LFV');</script> |
| <!-- End Google Tag Manager --> |
| |
| <div id="maincontent"> |
| <div id="midcolumn"> |
| |
| <h1><a name="top"></a>$pageTitle</h1> |
| |
| <blockquote> |
| <ul> |
| <li><a href="#motivation">Motivation</a></li> |
| <li><a href="#setup">Setup</a></li> |
| <li><a href="#running">Running a Report</a></li> |
| <li><a href="#passing_parameters">Passing Parameters</a></li> |
| <li><a href="#parameter_form">Parameter Form</a></li> |
| <li><a href="#dynamic">Generating Reports Dynamically</a></li> |
| </ul> |
| </blockquote> |
| |
| <h2><a name="motivation"></a>Motivation</h2> |
| <p> |
| BIRT is designed to be integrated into a Java EE web application. But, what if your |
| chosen development environment is something else, such as PHP? Can you still use |
| BIRT? Yes, you can. This page discusses how to use BIRT from PHP. |
| </p> |
| |
| |
| <h2><a name="setup"></a>Setup</h2> |
| <p> |
| PHP has the ability to call Java classes using a PHP/Java Bridge. So, one integration option is to have |
| the PHP engine call the BIRT Engine directly. The scenario is discussed in an article <a href="http://www.theserverside.com/tt/articles/article.tss?l=IntegratingBIRTwithPHP">here.</a> The examples associated with the |
| article are posted <a href=" http://www.birt-exchange.com/devshare/deploying-birt-reports/743-calling-birt-from-php/">here.</a> |
| </p><p> |
| Another option is to host BIRT on its own app server, such |
| as Tomcat, and use the <a href="/birt/phoenix/deploy/viewerUsageMain.php">BIRT Viewer URLs</a> to work |
| with BIRT. The rest of this page discusses this option. |
| </p> |
| <p> |
| The first step is to <a href="/birt/phoenix/deploy/viewerSetup.php">install Tomcat and the BIRT |
| viewer</a>. Let's assume that you've set up Tomcat on the same machine as the |
| web server running Apache, and that Tomcat listens on port 8080. Once the setup |
| works, we're ready to focus on the PHP side. |
| </p> |
| |
| |
| <h2><a name="running">Running a Report</a></h2> |
| <p> |
| Next step is to run a report from within a PHP script. Let's assume we have a report named test.rptdesign stored in C:/temp. We use a browser redirect to run the report. The redirect appears in an HTML header. Headers must be written before adding any content to the page: |
| </p> |
| <blockquote> |
| \$fname = "c:/temp/test.rptdesign";<br> |
| // Redirect browser<br> |
| \$dest = "http://localhost:8080/birt-viewer/run?__report=";<br> |
| \$dest .= urlencode( realpath( \$fname ) );<br> |
| header("Location: \$dest" );<br> |
| </blockquote |
| <p> |
| The name of the report is given as an absolute path, but a relative path is also |
| allowed once you set up the <code>BIRT_VIEWER_WORKING_FOLDER |
| </code> |
| configuration variable in the BIRT viewer web app's <code>web.xml </code>file. Be sure to |
| encode the file name for use in a URL. |
| </p> |
| |
| |
| <h2><a name="passing_parameters">Passing Parameters</a></h2> |
| <p> |
| Suppose your report takes parameters. The test report above has one parameter |
| called <code>sample</code>. We simply add them to the report URL in the form |
| described in <a href="/birt/phoenix/deploy/viewerUsageMain.php">Using the Report Viewer</a>. |
| </p> |
| <blockquote> |
| \$fname = "c:/temp/test.rptdesign";<br> |
| \$paramValue = "Hi there!";<br> |
| // Redirect browser<br> |
| \$dest = "http://localhost:8080/birt-viewer/run?__report=";<br> |
| \$dest .= urlencode( realpath( \$fname ) );<br> |
| \$dest .= ";sample=" . urlencode( \$paramValue );<br> |
| header("Location: \$dest" );<br> |
| </blockquote |
| <p> |
| The parameter value must also be encoded when placed into the URL. |
| </p> |
| |
| |
| <h2><a name="parameter_form">Parameter Form</a></h2> |
| <p> |
| Ideally, we could use PHP to create a UI form that prompts for the report |
| parameters. The BIRT viewer creates this form in Java using information in the |
| report design. Unfortunately, at present, there is no way to retrieve the raw |
| parameter descriptions from the BIRT viewer using a URL. Instead, there are two alternatives |
| we can use. |
| </p> |
| <p> |
| First, if we know the parameters ahead of time, we can design a custom form |
| in PHP that prompts the user for them. This works if we have a small number of |
| reports, or if we need to create a specialized parameter page for each report |
| anyway. |
| </p> |
| <p> |
| Second, we can let the BIRT viewer display the parameter page using the |
| <code>frameset</code> URL. |
| </p> |
| |
| |
| </div> |
| $deployLinksSideItem |
| </div> |
| |
| |
| EOHTML; |
| |
| |
| # Generate the web page |
| $App->generatePage($theme, $Menu, $Nav, $pageAuthor, $pageKeywords, $pageTitle, $html); |
| ?> |