Print content i class
Hejsa jeg er ved at lave min første class. den skal håndter templates til min hjemmeside.---------------------------------------
if (!class_exists('FastTemplate')) {
class FastTemplate {
var $file = ""; // The var there holds the content of our template.
function FastTemplate ( $template )
{
if( !file_exists( $template ) )
{
$this->error("Sorry but where not able to find the template (" .$template. ")", 1);
}
$this->file = implode('', file( $template ));
echo $this->file;
}
function parse ()
{
return( $this->$file );
exit;
}
function error ($errorMsg, $die = 0)
{
$this->ERROR = $errorMsg;
echo "ERROR: $this->ERROR <BR> \n";
if ($die == 1)
{
exit;
}
return;
} // end error()
}
}
---------------------------------
Min index.php
---------------------------------
require ("include/class.FastTemplate.php4");
$ftl = new FastTemplate( "templates/main.tpl" );
echo $ftl->parse();
---------------------------------
Men når jeg køre den får jeg beskdeden
---------------------------------
Fatal error: Cannot access empty property in /home/doomstone/Documents/www/include/class.FastTemplate.php4 on line 23
---------------------------------
Hvad har jeg gjort galt?
