Cep Posted July 10, 2006 Share Posted July 10, 2006 Hello,I am writing out a script from some sample code I picked up that would allow me to create template files in order to assemble pages using php variables.In order to do this I have a class file with the following code,[code]<?phpclass tpl {// eval ("\$membersbit .= \" ".$tpl->get("memberslist_membersbit")."\";"); Will output a internal template// eval("\$tpl->output(\"".$tpl->get("memberslist")."\");"); Will output an external frame template var $templates = array(); var $templatefolder = ""; /* constuctor */ function tpl($prefix="") { $this->templatefolder = $prefix."templates"; } function get($templatename, $folder = NULL) { if($folder==NULL) { $folder = ""; } if(!isset($this->templates[$templatename])) { if(file_exists($this->templatefolder.$folder."/$templatename.tpl")) { $this->templates[$templatename]=str_replace("\"","\\\"",implode("",file($this->templatefolder.$folder."/$templatename.tpl"))); } } return $this->templates[$templatename]; } /* print template */ function output($template) { headers::send(); $template = $this->$template; print($template); } function str_replace($search,$replace,$text) { if(strstr($text,$search)) { $x = strpos($text,$search); return substr($text,0,$x).$replace.substr($text,$x+strlen($search)); } else return $text; }}?>[/code]In my main index.php which I am going to call this class I have made a require statement at the top to the class.php file and I have then done the following,[code]<?phpsession_start();require "./lib/functions.php";require "./lib/class.php";$user = getcookie();eval("\$tpl->output(\"".$tpl->get("test")."\");");?>[/code]However I keep getting a Fatal error: Call to a member function on a non-object in c:\inetpub\wwwroot\budgetsys\index.php on line 8Any idea why? Link to comment https://forums.phpfreaks.com/topic/14160-call-to-a-member-function-on-a-non-object-in/ Share on other sites More sharing options...
Prismatic Posted July 10, 2006 Share Posted July 10, 2006 [code]<?phpsession_start();require "./lib/functions.php";require "./lib/class.php";$user = getcookie();$tpl = new tpl;eval("\$tpl->output(\"".$tpl->get("test")."\");");?>[/code] Link to comment https://forums.phpfreaks.com/topic/14160-call-to-a-member-function-on-a-non-object-in/#findComment-55464 Share on other sites More sharing options...
Cep Posted July 10, 2006 Author Share Posted July 10, 2006 Cheers Prismatic thought it would be something daft like that. I have a new error now but I think thats because of some missing code. Link to comment https://forums.phpfreaks.com/topic/14160-call-to-a-member-function-on-a-non-object-in/#findComment-55468 Share on other sites More sharing options...
Prismatic Posted July 10, 2006 Share Posted July 10, 2006 Good luck :) Link to comment https://forums.phpfreaks.com/topic/14160-call-to-a-member-function-on-a-non-object-in/#findComment-55470 Share on other sites More sharing options...
redarrow Posted July 10, 2006 Share Posted July 10, 2006 much faster <?phpsession_start();require_once ("./lib/functions.php");require_once ("./lib/class.php");$user = getcookie();$tpl = new tpl;eval("\$tpl->output(\"".$tpl->get("test")."\");");?> Link to comment https://forums.phpfreaks.com/topic/14160-call-to-a-member-function-on-a-non-object-in/#findComment-55513 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.