Error when using template system
Posted: Thu Feb 01, 2007 10:59 am
Everah | Please use
here is the main.php file
And here is the i_template.php which is supposed to work but doesnt i think.
Sorry its a little long but I have spent 2 weeks on this and I need help. Its for a freind.
Everah | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
hi guys
I am very new to php so if I mess up thats why.
I am using a template system and i keep on getting this errorCode: Select all
PHP Notice: Undefined variable: Page in C:\Inetpub\wwwroot\chapter8\main.php on line 5 PHP Warning: fopen(templates/.tpl) [function.fopen]: failed to open stream: No such file or directory in C:\Inetpub\wwwroot\chapter8\global\i_template.php on line 9 PHP Warning: filesize() [function.filesize]: stat failed for templates/.tpl in C:\Inetpub\wwwroot\chapter8\global\i_template.php on line 10 PHP Warning: fread(): supplied argument is not a valid stream resource in C:\Inetpub\wwwroot\chapter8\global\i_template.php on line 10 PHP Warning: fclose(): supplied argument is not a valid stream resource in C:\Inetpub\wwwroot\chapter8\global\i_template.php on line 11 PHP Notice: Undefined variable: Page in C:\Inetpub\wwwroot\chapter8\main.php on line 8 PHP Notice: Undefined variable: sessErrors in C:\Inetpub\wwwroot\chapter8\main.php on line 11Code: Select all
<?php
include_once("global/i_template.php");
session_start();
$strFileName = "templates/" . strtolower($Page) . ".tpl";
$objTemplate = new o_Template;
$objTemplate->m_LoadFile($strFileName);
$objTemplate->m_AddElements($Page);
if ($sessErrors)
{ $objTemplate->m_AssignContent("ERRORS", $sessErrors);
}
else
{ $objTemplate->m_AssignContent("ERRORS", "");
};
session_unregister("sessErrors");
$objTemplate->m_Output();
?>Code: Select all
<?php
class o_Template
{
var $p_strOutputContents = "";
var $p_arrSections = array();
var $p_arrPaired = array();
function m_LoadFile($strFile, $strTagName = "")
{ $objFile = fopen($strFile, "r");
$strContents = fread($objFile, filesize($strFile));
fclose($objFile);
if (empty($strTagName))
{ $this->p_strOutputContents = $strContents;
}
else
{ $this->p_strOutputContents = str_replace("{{" . $strTagName . "}}", $strContents, $this->p_strOutputContents);
};
}
function m_AssignContent($strTagName, $strReplace, $strContent="")
{
if (empty($strContent))
{ $this->p_strOutputContents = str_replace("{{" . $strTagName . "}}", $strReplace, $this->p_strOutputContents);
}
else
{ return str_replace("{{" . $strTagName . "}}", $strReplace, $strContent);
};
}
function m_DefineSection($strSectionName)
{ $longSectionStart = strpos($this->p_strOutputContents, "{{section $strSectionName }}");
$longSectionEnd = strpos($this->p_strOutputContents, "{{/section $strSectionName }}");
if (($longSectionEnd > 0))
{ $longSectionLength = $longSectionEnd - $longSectionStart + strlen("{{/section $strSectionName }}");
$strSection = substr($this->p_strOutputContents, $longSectionStart, $longSectionLength);
$this->p_arrSections[$strSectionName] = trim($strSection);
return $this->p_arrSections[$strSectionName];
};
}
function m_AssignSection($strSectionName, $strReplace, $strContent="")
{ $strSection = trim($this->p_arrSections[$strSectionName]);
if (empty($strContent))
{
if (!empty($strSection))
{ $this->p_strOutputContents = str_replace(trim($strSection), $strReplace . "\r\n" . $strSection, $this->p_strOutputContents);
};
}
else
{
if (!empty($strSection))
{ return str_replace($strSection, $strReplace . "\r\n" . $strSection, $strContent);
};
};
}
function m_DefinePair($strPairName, $boolUseBoth=false)
{ $longFirstStart = strpos($this->p_strOutputContents, "{{paired $strPairName }}");
$longFirstEnd = strpos($this->p_strOutputContents, "{{/paired $strPairName }}");
$longSecondStart = strpos($this->p_strOutputContents, "{{unpaired $strPairName }}");
$longSecondEnd = strpos($this->p_strOutputContents, "{{/unpaired $strPairName }}");
if (($longFirstEnd > 0))
{ $longFirstLength = $longFirstEnd - $longFirstStart + strlen("{{/paired $strPairName }}");
$longSecondLength = $longSecondEnd - $longSecondStart + strlen("{{/unpaired $strPairName }}");
$strFirstPairContents = substr($this->p_strOutputContents, $longFirstStart, $longFirstLength);
$strSecondPairContents = substr($this->p_strOutputContents, $longSecondStart, $longSecondLength);
$this->p_arrPaired[$strPairName][0] = trim($strFirstPairContents);
if ($boolUseBoth)
{ $this->p_arrPaired[$strPairName][1] = trim($strSecondPairContents);
}
return $this->p_arrPaired[$strPairName][0];
};
}
function m_AssignPair($strPairName, $strFirstReplace, $strSecondReplace="")
{ $strFirstPair = $this->p_arrPaired[$strPairName][0];
if (!empty($strFirstPair))
{ $this->p_strOutputContents = str_replace($strFirstPair, $strFirstReplace . "\r\n" . $strFirstPair, $this->p_strOutputContents);
if (!empty($strSecondReplace))
{ $strSecondPair = $this->p_arrPaired[$strPairName][1];
$this->p_strOutputContents = str_replace($strSecondPair, $strSecondReplace . "\r\n" . $strSecondPair, $this->p_strOutputContents);
};
};
}
function m_AddElements($strPageTitle)
{ $this->m_LoadFile("templates/navigation.tpl","NAVIGATION");
$this->m_LoadFile("templates/footer.tpl","FOOTER");
$this->m_AssignContent("TITLE","DWF - " . $strPageTitle);
}
function m_PrepTemplate($boolDeleteSection = true)
{
if ($boolDeleteSection)
{ $arrSections = $this->p_arrSections;
while (list($strSectionName, $strSectionContent) = each($arrSections))
{ $this->p_strOutputContents = str_replace(trim($strSectionContent), "", $this->p_strOutputContents);
$this->p_strOutputContents = str_replace("{{section " . $strSectionName . " }}", "", $this->p_strOutputContents);
$this->p_strOutputContents = str_replace("{{/section " . $strSectionName . " }}", "", $this->p_strOutputContents);
};
$arrPair = $this->p_arrPaired;
while (list($strPairName) = each($arrPair))
{
while (list($intArrayVal, $strPairContent) = each($arrPair["$strPairName"]))
{ $this->p_strOutputContents = str_replace(trim($strPairContent), "", $this->p_strOutputContents);
};
$this->p_strOutputContents = str_replace("{{paired " . $strPairName . " }}", "", $this->p_strOutputContents);
$this->p_strOutputContents = str_replace("{{/paired " . $strPairName . " }}", "", $this->p_strOutputContents);
$this->p_strOutputContents = str_replace("{{unpaired " . $strPairName . " }}", "", $this->p_strOutputContents);
$this->p_strOutputContents = str_replace("{{/unpaired " . $strPairName . " }}", "", $this->p_strOutputContents);
};
};
return $this->p_strOutputContents;
}
function m_Output()
{ echo $this->p_strOutputContents;
}
}
?>Everah | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]