HOWTO: Create a BVT Template for PHP

kclarkkclark BIRT GuruEM
edited January 2014 in DevShare Downloads
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.



Once BVT is installed on your application we'll use the following code for the template.
<HTML>
<BODY onload="init()">
<script type='text/javascript' language='JavaScript' src="http://localhost:8080/birt/jsapi"></script>
<script type='text/javascript'>
function init( ){
actuate.load('viewer');
actuate.initialize( "http://localhost:8080/birt", null,null,null,myInit );
}
function myInit(){
viewer1 = new actuate.Viewer( 'container1' );
viewer1.setReportDesign('{$name}');
viewer1.setSize({$width},{$height});
viewer1.submit( );
}
</script>
Hello {$name}!
<div id='container1' style=' border-width: 1px; border-style: solid;' />
</BODY>
</HTML>


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.
<?php

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

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

$smarty->assign('name', 'test.rptdesign');
$smarty->assign('height', '750');
$smarty->assign('width', '800');
$smarty->display('index.tpl');


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.

Kristopher Clark

Actuate Corporation – The BIRT Company™

http://www.actuate.com | http://birtondemand.com

 

My Blog

Twitter

LinkedIn
Facebook
 

Sign In or Register to comment.