Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 找不到Smarty_Internal_TemplateCompiler数据库_Php_Smarty_Composer Php_Autoload_Spl Autoload Register - Fatal编程技术网

Php 找不到Smarty_Internal_TemplateCompiler数据库

Php 找不到Smarty_Internal_TemplateCompiler数据库,php,smarty,composer-php,autoload,spl-autoload-register,Php,Smarty,Composer Php,Autoload,Spl Autoload Register,composer.json: { "require": { "smarty/smarty": "v3.1.17" } } index.php: define('SMARTY_SPL_AUTOLOAD', 1); // now smarty should use its own autoloader require_once __DIR__ . "/vendor/autoload.php"; function my_classes_loader($class) { $pa

composer.json:

{
  "require": {
    "smarty/smarty": "v3.1.17"
  }
}
index.php:

define('SMARTY_SPL_AUTOLOAD', 1); // now smarty should use its own autoloader

require_once __DIR__ . "/vendor/autoload.php";

function my_classes_loader($class) {
  $path = "{$class}.class.php";

  if (file_exists($path)) {
    include_once $path;
    return true;
  }

  return false;
}

spl_autoload_register('my_classes_loader');

$smarty = new Smarty();
$smarty->setCompileDir("templates_c");

$smarty->display('main.html');

exit();
如果我在浏览器中打开它,我会

致命错误:在中找不到类“Smarty\u Internal\u TemplateCompilerBase” //smarty示例/vendor/smarty/smarty/distribution/libs/sysplugins/smarty_internal_smartytemplatecompiler.php 在线XX

文件在那里。它有内容。对于PHP等,它是可访问/可读的


我做错了什么?缺少什么?

只有一点决定自动加载是个好主意,这应该是作曲家一个人

尝试将自己的自动加载函数放在一边,改为在composer.json中使用自动加载声明。不幸的是,您并没有使用PSR-0或PSR-4命名标准,但Composer允许您在这种情况下使用“类映射”。考虑将所有文件名移动到符合PSR-0.

smarty自动加载应该已经通过Composer完成了。不需要设置该常数

最后但并非最不重要的一点是,我认为您的自动加载功能不应该返回任何内容。特别是,如果它找不到它假定包含该类的文件,则不应返回false,因为根据自动加载函数在堆栈上的顺序,可能会首先为所有类(包括所有Smarty类)调用函数。如果在这些情况下返回false,则不允许以后的函数加载该类,从而破坏正在工作的自动加载堆栈

所以总的来说,最好使用Composer进行所有自动加载。开发人员尽一切努力提供性能最好的自动加载功能-您自己的功能可能只能和他们的一样快,但可能会更慢