请大家帮我看下这是什么错误

iScript 2012-02-14 12:41:45
类的自动加载别的类都可以自动加载就是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行

?>
...全文
151 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
iScript 2012-02-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 foolbirdflyfirst 的回复:]
Tpl做了单例处理,Tpl类实例化的的时候要 $tpl = Tpl::getInstance()这么调用,不能直接new Tpl().
[/Quote]

我写的是$smarty = Tpl::getInstance(); 这样也不行啊
foolbirdflyfirst 2012-02-14
  • 打赏
  • 举报
回复
Tpl做了单例处理,Tpl类实例化的的时候要 $tpl = Tpl::getInstance()这么调用,不能直接new Tpl().
iScript 2012-02-14
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 mengxiangbaidu 的回复:]
去掉define('ROOT_PATH', dirname(__FILE__));
[/Quote]

貌似没用啊!~~
coder 2012-02-14
  • 打赏
  • 举报
回复
去掉define('ROOT_PATH', dirname(__FILE__));
coder 2012-02-14
  • 打赏
  • 举报
回复

<?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);
iScript 2012-02-14
  • 打赏
  • 举报
回复
试了大半天了,好像是smarty的问题
我用最新版的smarty就出错 用了2点几版本的smarty就可以了!~

不过如何和最新版的兼容呢 把private去掉也不行
要改我的程序还是改smarty啊?
xb12369 2012-02-14
  • 打赏
  • 举报
回复
太复杂了!!!!
coder 2012-02-14
  • 打赏
  • 举报
回复
源代码这个
private function __construct(){
$this->setConfigs();
}

private不能加。去掉,默认的就可以了
foolbirdflyfirst 2012-02-14
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 iscript 的回复:]

我改成 $tpl = Tpl::getInstance()

Tpl类里private都改成public还是不行啊 晕!~~
[/Quote]

报什么错?你简化下问题,自己开个页面测试

class Smarty{ 
public __construct(){}
}
class Tpl extends Smarty{
private __construct(){}//这样肯定报错,报和你主贴同样的错误。因为private > public
}
iScript 2012-02-14
  • 打赏
  • 举报
回复
我改成 $tpl = Tpl::getInstance()

Tpl类里private都改成public还是不行啊 晕!~~
foolbirdflyfirst 2012-02-14
  • 打赏
  • 举报
回复
那就是因为你的Smarty类的构造函数(__construct)访问权限是public,根据oo规则,子类复写的同一方法,访问权限必须低于父类的,所谓的高低关系为(private > protected > public)

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧