0

我在配置 smarty 3.1.12 版本时遇到了一些问题。

当我尝试从数据库中提取一些数据时,它运行“致命错误:在 F:...\smarty\sysplugins\smarty_internal_templatebase.php 第 47 行调用非对象上的成员函数 createTemplate()”

但是如果程序没有从数据库中提取,它运行正常。例如:

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

下面是我正在使用的代码。

公司.php

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

$smarty = new Smarti();
?>

系统.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");      
    }
}
?>

我不知道哪里出错了。我可以通过其他方式从数据库中提取数据,所以这不是数据库问题。你们能帮帮我吗?谢谢~

4

1 回答 1

3

Smarty constructor成员变量设置为自身。从constructor您的扩展Smarti课程中进行。

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

但最好调用 Smarty 构造函数本身。

class Smarti extends Smarty{
  function Smarti() {
    parent::__construct();
    ...
于 2012-10-27T01:24:42.113 回答