类的自动加载别的类都可以自动加载就是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行?>

解决方案 »

  1.   

    Tpl做了单例处理,Tpl类实例化的的时候要 $tpl = Tpl::getInstance()这么调用,不能直接new Tpl().
      

  2.   


    我写的是$smarty = Tpl::getInstance();  这样也不行啊  
      

  3.   

    那就是因为你的Smarty类的构造函数(__construct)访问权限是public,根据oo规则,子类复写的同一方法,访问权限必须低于父类的,所谓的高低关系为(private > protected > public)
      

  4.   

    我改成  $tpl = Tpl::getInstance()Tpl类里private都改成public还是不行啊 晕!~~
      

  5.   


    报什么错?你简化下问题,自己开个页面测试class Smarty{ 
      public __construct(){}
    }
    class Tpl extends Smarty{
      private __construct(){}//这样肯定报错,报和你主贴同样的错误。因为private > public
    }
      

  6.   

    源代码这个
    private function __construct(){
    $this->setConfigs();
    }

    private不能加。去掉,默认的就可以了
      

  7.   

    试了大半天了,好像是smarty的问题
    我用最新版的smarty就出错   用了2点几版本的smarty就可以了!~不过如何和最新版的兼容呢 把private去掉也不行
    要改我的程序还是改smarty啊?
      

  8.   


    <?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);
      

  9.   

    去掉define('ROOT_PATH', dirname(__FILE__));