Matt
Matt

Reputation: 565

smarty - Fatal Error: Call to a member function createTemplate() on a non-object

I've got some problems when configuring smarty, version 3.1.12.

When I try to extract some data from database, it runs "Fatal error: Call to a member function createTemplate() on a non-object in F:...\smarty\sysplugins\smarty_internal_templatebase.php on line 47"

But if the program does NOT extract from database, it runs ok. For example:

<?php
include "smarty/smarty.class.php";
$smarty->assign('title', 'I'm title');
$smarty->assign('content', 'I'm content');
$smarty->display('test.html');
?>

Below is the codes I'm using.

inc.php

<?php
// Load smarty class file.
require("sys.smarty.php");

$smarty = new Smarti();
?>

sys.smarty.php

<?php

// Load smarty class file.
require("smarty/smarty.class.php");

class Smarti extends Smarty{
    function Smarti() {
        $this->setTemplateDir("../smarty/templates");
        $this->setConfigDir("../smarty/configs");
        $this->setCompileDir("../smarty/templates_c");
        $this->setCacheDir("../smarty/cache");      
    }
}
?>

I don't know where went wrong. I can extract data from database in some other way, so it's not the database problem. Could u guys lend me a hand? Thx~

Upvotes: 0

Views: 5302

Answers (1)

air4x
air4x

Reputation: 5683

The Smarty constructor sets a member variable to itself. Do it from the constructor of your extended Smarti class.

class Smarti extends Smarty{
  function Smarti() {
    $this->smarty = $this;
    ...

But it would be better to call the Smarty constructor itself.

class Smarti extends Smarty{
  function Smarti() {
    parent::__construct();
    ...

Upvotes: 3

Related Questions