[英]Include smarty in php's __autoload gives Class 'Smarty_Internal_Template' not found
I have a autoload function like this: 我有这样的自动加载功能:
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;
}
}
I renamed the smarty file to class.smarty.inc.php
so it's included in the autoload, but I get this error: 我将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
Don't know what that mean.. 不知道那是什么意思..
Do NOT modify 3rd-party-libraries. 不要修改第三方的库。 Just create a second autoloader that follows Smarty's naming convention. 只需按照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');
The way your autoloader maps the classname to a filename leads to the filename class.smarty_internal_template.inc.php
, which is obviously not the filename you expect. 自动加载器将类名映射到文件名的方式会导致文件class.smarty_internal_template.inc.php
,这显然不是您期望的文件名。 I dont know how Smarty is structured, but you should make sure the autoloader can find any of its classes. 我不知道Smarty是如何构造的,但你应该确保自动加载器可以找到它的任何类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.