Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] help with template class

[SOLVED] help with template class

 
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 05-20-08, 09:57 PM
darkcarnival's Avatar
darkcarnival darkcarnival is offline
PHP/MySQL coder
 
Join Date: Jun 2003
Location: Michigan
Posts: 939
Thanks: 0
Thanked 0 Times in 0 Posts
Hazard [SOLVED] help with template class

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
__________________
Elite Bulletin Board
http://elite-board.us
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
improving my template class darkcarnival PHP 4 05-23-07 01:11 PM
conceptual problem: abstract class, interface or class UnrealEd Everything Java 2 05-12-07 08:30 AM
I need to pass this class Please Help! Negative6 Everything Java 1 05-03-07 07:55 AM
how to loop mysql into template system??? how u guys make it??? Eric Hadson PHP 0 09-19-05 11:43 PM
Good template system [PL]Greg PHP 3 06-28-03 05:09 AM


All times are GMT -5. The time now is 12:43 PM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.