在php的__autoload中包含smarty,找不到类'Smarty_Internal_Template'

时间:2011-03-29 17:20:35

标签: php smarty template-engine

我有这样的自动加载功能:

function __autoload($class)
{
    //define('DOCROOT', dirname(__FILE__));

    $filename = "../sys/class/class." . strtolower($class) . ".inc.php";
    //$filename = DOCROOT . "/sys/class/class." . strtolower($class) . ".inc.php";

    if ( file_exists($filename) )
    {
            include_once $filename;
    }

}

我将smarty文件重命名为class.smarty.inc.php,因此它包含在自动加载中,但我收到此错误:

Fatal error: Class 'Smarty_Internal_Template' not found in /var/www/v3/sys/class/class.smarty.inc.php on line 441 

不知道那是什么意思..

2 个答案:

答案 0 :(得分:2)

修改第三方库。只需按照Smarty的命名惯例创建第二个自动加载器。

function defaultAutoloader($className) {
    // your code ($file = /path/to/my/lib/{{ CLASS }}.inc.php)

    if (file_exists($file)) {
        require $file;
        return true;
    }

    return false;
}

function smartyAutoloader($className) {
    // code ($file = /path/to/smarty/{{ CLASS }}.php)

    if (file_exists($file)) {
        require $file;
        return true;
    }

    return false;
}

spl_autoload_register('defaultAutoloader');
spl_autoload_register('smartyAutoloader');

答案 1 :(得分:0)

自动加载器将类名映射到文件名的方式会导致文件名class.smarty_internal_template.inc.php,这显然不是您期望的文件名。我不知道Smarty是如何构建的,但你应该确保自动加载器可以找到它的任何类。

相关问题