类的自动加载别的类都可以自动加载就是tpl类不能自动加载
Fatal error: Class 'Tpl' not found in D:\AppServ\www\yshop\configs\run.inc.php on line 22我手动 require ROOT_PATH.'/public/Tpl.class.php';又出现这个错误
Fatal error: Access level to Tpl::__construct() must be public (as in class Smarty) in D:\AppServ\www\yshop\public\Tpl.class.php on line 46<?php
class Tpl extends Smarty{
static private $instance;
static public function getInstance(){
if(!(self::$instance instanceof self)){
self::$instance = new self();
}
return self::$instance;
}
private function __clone(){
} private function __construct(){
$this->setConfigs();
}
private function setConfigs(){
//模板目录
$this->template_dir = ROOT_PATH.'/view/';
//编译目录
$this->compile_dir = ROOT_PATH.'/compile/';
//配置变量目录
$this->config_dir = ROOT_PATH.'/configs/';
//缓存目录
$this->cache_dir = ROOT_PATH.'/cache/';
//是否开启缓存,网站开发调试阶段,我们应该关闭缓存
$this->caching = 0;
//缓存的声明周期
$this->cache_lifetime = 60*60*24;
//左定界符
$this->left_delimiter = '{';
//右定界符
$this->right_delimiter = '}';
}
} 这里是46行?>
Fatal error: Class 'Tpl' not found in D:\AppServ\www\yshop\configs\run.inc.php on line 22我手动 require ROOT_PATH.'/public/Tpl.class.php';又出现这个错误
Fatal error: Access level to Tpl::__construct() must be public (as in class Smarty) in D:\AppServ\www\yshop\public\Tpl.class.php on line 46<?php
class Tpl extends Smarty{
static private $instance;
static public function getInstance(){
if(!(self::$instance instanceof self)){
self::$instance = new self();
}
return self::$instance;
}
private function __clone(){
} private function __construct(){
$this->setConfigs();
}
private function setConfigs(){
//模板目录
$this->template_dir = ROOT_PATH.'/view/';
//编译目录
$this->compile_dir = ROOT_PATH.'/compile/';
//配置变量目录
$this->config_dir = ROOT_PATH.'/configs/';
//缓存目录
$this->cache_dir = ROOT_PATH.'/cache/';
//是否开启缓存,网站开发调试阶段,我们应该关闭缓存
$this->caching = 0;
//缓存的声明周期
$this->cache_lifetime = 60*60*24;
//左定界符
$this->left_delimiter = '{';
//右定界符
$this->right_delimiter = '}';
}
} 这里是46行?>
我写的是$smarty = Tpl::getInstance(); 这样也不行啊
报什么错?你简化下问题,自己开个页面测试class Smarty{
public __construct(){}
}
class Tpl extends Smarty{
private __construct(){}//这样肯定报错,报和你主贴同样的错误。因为private > public
}
private function __construct(){
$this->setConfigs();
}
的
private不能加。去掉,默认的就可以了
我用最新版的smarty就出错 用了2点几版本的smarty就可以了!~不过如何和最新版的兼容呢 把private去掉也不行
要改我的程序还是改smarty啊?
<?php
require 'Smarty.class.php';class Tpl extends Smarty {
private static $instance;
static public function getInstance() {
if (! (self::$instance instanceof self)) {
self::$instance = new self ();
}
return self::$instance;
}
public function __clone() {
}
public function __construct() {
$this->setConfigs ();
}
private function setConfigs() {
define('ROOT_PATH', dirname(__FILE__));
// 模板目录
$this->template_dir = ROOT_PATH . '/view/';
// 编译目录
$this->compile_dir = ROOT_PATH . '/compile/';
// 配置变量目录
$this->config_dir = ROOT_PATH . '/configs/';
// 缓存目录
$this->cache_dir = ROOT_PATH . '/cache/';
// 是否开启缓存,网站开发调试阶段,我们应该关闭缓存
$this->caching = 0;
// 缓存的声明周期
$this->cache_lifetime = 60 * 60 * 24;
// 左定界符
$this->left_delimiter = '{';
// 右定界符
$this->right_delimiter = '}';
}
} //$i = Tpl::getInstance();
//var_dump($i);