在学习php从入门到精通里面的smarty时,如果你下载的是smarty3版本,对smarty进行封装时会一直报两个错误
smarty3 一直报错这两个错误Trying to get property of non-object in和Call to a member function create() on null in
原因是没有继承Smarty.class.php里面的构造函数
从而找不到模版文件
在system.smarty.inc.php文件里面添加 parent::__construct(); 即可
<?php
define('BASE_PATH',$_SERVER['DOCUMENT_ROOT']);
define('SMARTY_PATH','/smarty/');
require BASE_PATH.SMARTY_PATH.'Smarty.class.php';
class SmartyProject extends Smarty{
function SmartyProject(){
parent::__construct(); //这里添加继承父级构造函数就解决了
$this->template_dir=BASE_PATH.SMARTY_PATH."templates/";
$this->compile_dir=BASE_PATH.SMARTY_PATH."templates_c/";
$this->config_dir=BASE_PATH.SMARTY_PATH."configs/";
$this->cache_dir=BASE_PATH.SMARTY_PATH."cache/";
}
}
?>