Jump to content

Call to a member function on a non-object in


Cep

Recommended Posts

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]
<?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;
  }
}
?>
[/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]
<?php
session_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 8

Any idea why?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.