Jump to content


Photo

Call to a member function on a non-object in


  • Please log in to reply
4 replies to this topic

#1 Cep

Cep
  • Members
  • PipPipPip
  • Advanced Member
  • 539 posts
  • LocationOn a boat in the middle of nowhere

Posted 10 July 2006 - 11:00 AM

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,

<?php
class 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;
  }
}
?>

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,

<?php
session_start();
require "./lib/functions.php";
require "./lib/class.php";

$user = getcookie();

eval("\$tpl->output(\"".$tpl->get("test")."\");");

?>

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 8

Any idea why?

Thanks Cep

#2 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 10 July 2006 - 11:10 AM

<?php
session_start();
require "./lib/functions.php";
require "./lib/class.php";

$user = getcookie();

$tpl = new tpl;
eval("\$tpl->output(\"".$tpl->get("test")."\");");

?>


#3 Cep

Cep
  • Members
  • PipPipPip
  • Advanced Member
  • 539 posts
  • LocationOn a boat in the middle of nowhere

Posted 10 July 2006 - 11:13 AM

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.
Thanks Cep

#4 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 10 July 2006 - 11:17 AM

Good luck :)

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 10 July 2006 - 01:02 PM

much faster

<?php
session_start();
require_once ("./lib/functions.php");
require_once ("./lib/class.php");

$user = getcookie();

$tpl = new tpl;
eval("\$tpl->output(\"".$tpl->get("test")."\");");

?>
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users