Author Topic: grab() prints contents and returns empty string?  (Read 1467 times)

0 Members and 1 Guest are viewing this topic.

MaxOfLondon

  • Guest
grab() prints contents and returns empty string?
on: Fri, 11. July 2003 - 14:22:32
Hi

I am using 2 vLibTemplates and vLibMimeMail in the same page.
The first vLibTemplate object called $tpl is used to display a page. The second vLibTemplate object $mailtpl is used to grab contents of template file and pass as contents to $email (vLibMimeMail).

The structure looks something like that:

Code: [Select]
$tpl = new vLibTemplate'page.tpl';

$mailtpl = new vLibTemplate'mail.tpl';

...

if somecond

    $email = new vLibMimeMail;

    $email-to'[email protected]';

    ...

    $contents = $mailtpl-grab;

    $email-htmlbody = $contents;

    $email-send;





$tpl-pparse;


I have the following problem with this implementation.
The
Code: [Select]
$contents = $mailtpl-grab actually displays email and then program fails on $email->send() because $contents is empty (Fatal error: vlibMimeMail error: Tried to send a message with no body. in c:apachehtdocslibvlibMimeMailerror.php on line 55).

Does any one know of why this happens or if vLibTemplate uses some temp file for parsing that can be accessed by both templates? Please help. I have been trying to fix it for couple of days now and see no resolution.

MaxOfLondon

  • Guest
grab() prints contents and returns empty string?
Reply #1 on: Fri, 11. July 2003 - 15:27:02
I think I have found it but still working on it.

the vLibTemplate uses callback function for output buffering and in some server and PHP configurations this does not work very well. I will investigate further and update you.

MaxOfLondon

  • Guest
grab() prints contents and returns empty string?
Reply #2 on: Fri, 11. July 2003 - 19:10:49
After investigating vLibTemplate class I have found that priate function _parse ($compress='') initialises turns on output buffering with callback function that's name is kept in $compress var.
By default $compress is set to '' (empty string). This seems to be responsible for the problem. The grab function calls _parse() with no $compress value set hence ob_start() is called with empty string namely ob_start('').

To rectify problem I have simply changed ob_start($compress) to ob_start(). I do not use compression for pages and this solution is OK for me.

I suggest following changes to people with similar problems:
In vLibTemplate class changes in function _parse ($compress=''):
line:
Code: [Select]
ob_start$compress;
to:
Code: [Select]
if empty$compress

    ob_start;

else

    ob_start$compress;


cheers
Max

releasedj

  • Guest
grab() prints contents and returns empty string?
Reply #3 on: Sat, 12. July 2003 - 01:24:24
I think this has already been fixed in CVS (although I'm not sure). By changing the function declaration to $compress=null the problem should be solved without losing any functionality.

Kelvin