TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-27-2010, 03:44 AM   #1 (permalink)
The Contributor
 
tego10122's Avatar
 
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
tego10122 is on a distinguished road
Default Template Class Issue

Hello,

I'm having a issue with my template class. I need to output a while statement from user.functions.php but when I do the following.

Code:
$template = new tpl();
$template->set_template('user_profile.phtml');
$template->write('feed', randomUserFeedFunction());
$template->render();
Heres the issue
Instead of Outputting :

Code:
 
Feed message one 1 
Feed message two 2 
etc.
in the .feed div it out put it at the top of the template . Why?

Code:
<?PHP

class template{
	protected $file;
	protected $values = array();
	

	public function __construct(){	}
	
	# Loads and sets template file
	public function set_template($file){
		$this->file = $file;
	}
	# Set 
	public function set($key, $value){
		$this->values[$key] = $value;
	}
	# Output
	public function output(){
		if(!file_exists($this->file)){
			return '<fieldset style="background:#FFF;padding:5px;border:1px solid #CCC;"><legend><strong style="color:red;">ERROR</strong></legend>File ('.$this->file.') doesn\'t exist.</fieldset>';
		}
		$output = file_get_contents($this->file);
		
		foreach($this->values as $key => $value){
			$tagToReplace = "{".$key."}"; # Find {KEY}
			$output = str_replace($tagToReplace, $value, $output);
		}
		return $output;
	}
	# Render Template
	public function render(){
		print $this->output();
	}
}
__________________
You're Everyday Graphic Artist
Twitter|GigPark|Linked In
Send a message via MSN to tego10122
tego10122 is offline  
Reply With Quote
Old 12-28-2010, 07:08 PM   #2 (permalink)
The Acquainted
 
wGEric's Avatar
 
Join Date: Nov 2007
Posts: 166
Thanks: 0
wGEric is on a distinguished road
Default

Your template class isn't matching up with the first code you posted. Is there another class that is named tpl? Reason I ask is there isn't a write method in your code. I'm guessing the issue is in that method.
__________________
Eric
wGEric is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
base classes..... allworknoplay Absolute Beginners 16 05-10-2009 08:09 PM
Template Class Issues WinSrev Advanced PHP Programming 20 11-04-2008 05:05 PM
[Tutorial] Basic tutorial about class basics Tanax Absolute Beginners 14 07-24-2008 01:37 PM
Pure PHP template class. abiko Advanced PHP Programming 1 04-02-2008 05:45 PM
PHP5 Classes A to Z Part 1 quantumkangaroo Advanced PHP Programming 11 04-01-2008 04:21 AM


All times are GMT. The time now is 10:11 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design