...

View Full Version : Simple Template Class



Saj
12-01-2003, 10:18 PM
Hey,

I'm working on a simple template class at the moment to incorporate with my message board, but have stumbled on a few problems.....

This is my code for the Error Template:



class ErrorTemplate {
function ErrorTemplate($Error, $MySQLError) {
return <<<HTML
<!-- My HTML -->
HTML;
}
}


And my Error Function in my actual Message Board Class:



function Error($Error, $MySQLError = '') {
require('Error.tpl.php');
$ErrorTemplate = new ErrorTemplate($Error, $MySQLError);
return false;
}


Well first off, I get this error message:



Parse error: parse error, unexpected $end in c:\web\www\php\mb\mysql class\phpWWWBoard\Error.tpl.php on line 29

Fatal error: Cannot instantiate non-existent class: errortemplate in c:\web\www\php\mb\mysql class\phpWWWBoard\phpWWWBoard.php on line 51


However, it seems that when I remove the spaces before return <<<HTML and HTML;, the error goes away, but the HTML doesnt show up. I have not been able to get any of the HTML to show up, actually, and can't see what I'm doing wrong.

Any help would be appreciated.

nicklim
12-02-2003, 05:12 AM
hmm i am going to need more of error.tpl.php to know what's going on..

class ErrorTemplate {
function ErrorTemplate($Error, $MySQLError) {
return <<<HTML
<!-- My HTML -->
HTML;
}
}
feels wrong.. return <<< HTML ?..
try
class ErrorTemplate {
function ErrorTemplate($Error, $MySQLError) {
$HTML.= "<!-- My HTML --> HTML....";
return $HTML;
}
}

this should work.. i don't know what are you doing with return <<< HTML
(maybe add a echo $HTML; also.. )

Spookster
12-02-2003, 07:14 AM
If you are going to use heredoc syntax then you need to make sure you set it up properly. In your case you would be better off storing the the value of your heredoc statement in a variable and then returning the variable.




class ErrorTemplate {
function ErrorTemplate($Error, $MySQLError) {
$html = <<<HTML
<!-- My HTML -->
HTML;
return $html;
}
}



Note when using heredoc syntax the ending command must be flush up against the left side. Or in other words it must be the first thing on that line with no spaces before it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum