Smarty报错 Call to a member function createTemplate() on a non-object 本帖最后由 cnbsd 于 2012-05-04 16:03:04 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 smarty 对象为初始化。关键的部分没贴出来。 已经贴了啊,没贴的smarty类文件Smarty.class.php是下载的! createTemplate() 函数在哪定义的 不知道你是如何使用的abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data这是一的抽象类,没有定义 createTemplate() 方法你必须在继承类中自行定义,或许已在 Smarty_Internal_Data 中定义过了也未可知不过既然是 member function createTemplate() on a non-object 显然是继承类没有实例化或者是对象被关在外边了 说不定 smarty包 缺少文件呢 没有引用正确,按照楼主的目录结构: |--Smarty.class.php |--system |--system.inc.php |--system.smarty.inc.phpsystem.smarty.inc.php文件中:require '../Smarty.class.php'; 这么引用会报错Warning: require(../Smarty.class.php) [function.require]: failed to open stream: No such file or directory in 再试试:require (dirname(__FILE__)."/../Smarty.class.php"); public function __construct() { parent::__construct(); $this->template_dir = 'templates/'; $this->compile_dir = 'templates_c/'; $this->config_dir = 'configs/'; $this->cache_dir = 'cache/';} 眼神果然犀利 , 一眼就看出继承了 Smarty , 并且自己使用了 __construct 那么 smarty 的构造方法就不会运行 , 所以 parent::__construct 才是正解 .斑猪们不行啊 . 求一个php写的正则替换 网站连接问题 IF语句出问题 关于使用json_encode从php向JavaScript传递多维数组会出错的问题。 php服务器的名字无效? PHP5 socket_recv 求助 如何建立目录多级目录 xampp无法启动apache 一个表单两个提交怎么解决 如何禁止用户重复登录(急,在线等) 怎么用curl或者file_get_contents 采集重定向之前的页面内容呢? mysqli连接数据库问题
已经贴了啊,没贴的smarty类文件Smarty.class.php是下载的!
abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
这是一的抽象类,没有定义 createTemplate() 方法你必须在继承类中自行定义,或许已在 Smarty_Internal_Data 中定义过了也未可知
不过既然是 member function createTemplate() on a non-object 显然是继承类没有实例化或者是对象被关在外边了
没有引用正确,按照楼主的目录结构:
|--Smarty.class.php
|--system
|--system.inc.php
|--system.smarty.inc.phpsystem.smarty.inc.php文件中:
require '../Smarty.class.php';
这么引用会报错
Warning: require(../Smarty.class.php) [function.require]: failed to open stream: No such file or directory in
public function __construct() {
parent::__construct();
$this->template_dir = 'templates/';
$this->compile_dir = 'templates_c/';
$this->config_dir = 'configs/';
$this->cache_dir = 'cache/';
}
眼神果然犀利 , 一眼就看出继承了 Smarty , 并且自己使用了 __construct 那么 smarty 的构造方法就不会运行 , 所以 parent::__construct 才是正解 .
斑猪们不行啊 .