HOWTO: Create a BVT Template for PHP

kclark
kclark E
edited February 11, 2022 in Analytics #1
The Birt Viewer Toolkit (BVT) is a new free viewer for the BIRT developer community. One of it's strengths is the JavaScript API (JSAPI). By making use of the JSAPI we can easily create a template that can be reused in your PHP Project to embed your BIRT reports. If you're unfamiliar with the Smarty project, I suggest taking a look at their website.<br />
<br />
Once BVT is installed on your application we'll use the following code for the template.
&lt;HTML&gt;
&lt;BODY onload="init()"&gt;
&lt;script type='text/javascript' language='JavaScript' src="http&#58;//localhost:8080/birt/jsapi"&gt;&lt;/script&gt;
&lt;script type='text/javascript'&gt;
function init( ){
actuate.load('viewer');
actuate.initialize( "http&#58;//localhost:8080/birt", null,null,null,myInit );
}
function myInit(){
viewer1 = new actuate.Viewer( 'container1' );
viewer1.setReportDesign('{$name}');
viewer1.setSize({$width},{$height});
viewer1.submit( );
}
&lt;/script&gt;
Hello {$name}!
&lt;div id='container1' style=' border-width: 1px; border-style: solid;' /&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;
<br />
If you're familiar with PHP you'll notice I've use variable for name, height, and width to make this template dynamic. This will allow for easier changes down the road when you want to embed another report somewhere else. Now that we've got the template we can use it in some PHP using the following.
&lt;?php

// put full path to Smarty.class.php
require('/usr/local/lib/php/Smarty/Smarty.class.php');
$smarty = new Smarty();

$smarty-&gt;setTemplateDir('/usr/local/www/apache24/data/web/smarty/templates');
$smarty-&gt;setCompileDir('/usr/local/www/apache24/data/web/smarty/templates_c');
$smarty-&gt;setCacheDir('/usr/local/www/apache24/data/web/smarty/cache');
$smarty-&gt;setConfigDir('/usr/local/www/apache24/data/web/smarty/configs');

$smarty-&gt;assign('name', 'test.rptdesign');
$smarty-&gt;assign('height', '750');
$smarty-&gt;assign('width', '800');
$smarty-&gt;display('index.tpl');
<br />
If all went well you should have a report that is embedded inside your PHP page. If you need to find some more information on Actuate's JSAPI or have any questions make sure to check out the deployment center or ask on the forums.
Warning No formatter is installed for the format ipb