hi,
I'm trying to get a template class of mine to work correctly, but during the part of the code that should be outputting the parsed data, I get this error:
Quote:
|
Warning: Invalid argument supplied for foreach() on line 60
|
now I'm using a foreach as the template will be working with loops and I'm trying to make it all work on one template file(meaning using one tremplate for a loop action not separating it into 3) as currently my template file count is at 160 and I wish to cut that down a bit for ease
now here is the template class I'm using:
PHP Code:
class templateEngine implements templateCore{
#declare data members
private $output;
private $tags = array();
private $templateFile;
#function that will open template file.
public function __construct($file){
#see if template file exists.
if (!file_exists($file)){
throw new Exception('Template file ('.$file.') was not found.');
}else{
#get the contents of the template file
$contents = file_get_contents($file);
#see if template file is empty.
if(empty($contents)){
throw new Exception('Template file is empty.');
}else{
#Add template contents into output variable.
$this->output = $contents;
}
}
}
#function that will parse template tags.
public function parseTags($tags){
if(count($tags)<1){
throw new Exception('No tags were found to be parsed.');
}
foreach($tags as $tag=>$data){
#if data is array, traverse recursive array of tags
if(is_array($data)){
$this->output = preg_replace("/\{$tag/",'',$this->output);
}
$this->output = str_replace('{'.$tag.'}', $data, $this->output);
}
}
#function that will output the final set.
public function outputHtml(){
$html = '';
foreach($this->output as $val){
$html .= $val;
}
return $html;
}
}
I have tried several things and so far I haven't gotten far. I hope something here knows why this doesn't work. If you need any thing else, please let me know.
much thanks in advanced
