This topic is locked

PDF View Bug

4/29/2008 1:10:39 PM
PHPRunner General questions
S
spintz author

PDF View wasn't working for me. If only 1 record was returned there would be a second record displayed where data seemed corrupt/invalid.
The problem was that I have events that add key/value pairs to the $data associative array and these events are called during the smarty fetch. In view.php around line 311, inside the -

##if @BUILDER.bViewPDF##

##endif##


section, the following 2 lines do not occur in the correct order -

$data=db_fetch_array($rs);

$page = $smarty->fetch($templatefile);


The next record is pulled from the database, THEN the templatefile is processed. This is ok, because the data from the previous record is assigned to smarty variables at this point, so it's not needed. However, the check for if there are more records simply does -

while($data)


and since my events assign values to the $data array, it's never null, which causes the while loop to never end and simply error out when the data for the record does not exist. So, simply making the DB fetch happen AFTER the smarty template file processing, solves this issue, since any events that occur inside the smarty template processing that may modify $data will be discard and $data will properly be null for the while($data) check and stop processing data!
I'm posting this here, instead of just emailing in case anyone else was having similar issues and wanted a fix for it. Just make the db_fetch_array call happen AFTEr the $smarty->fetch call.

Alexey admin 4/30/2008

Hi,
your suggestion seems reasonable.

We'll make View page compatible with your event code.
Right now you can swap these two lines in view.php:

$page = $smarty->fetch($templatefile);

$data=db_fetch_array($rs);



and rebuild your project.