简体   繁体   English

Smarty和NetBeans自动加载冲突

[英]Smarty and NetBeans autoload conflict

I have started learning NetBeans and tried to implement Smarty template engine in their To-Do example. 我已经开始学习NetBeans,并尝试在他们的To-Do示例中实现Smarty模板引擎。 When i try to run app, i get error: "Class "Smarty_Internal_TemplateCompilerBase" not found." 当我尝试运行应用程序时,出现错误:“找不到类“ Smarty_Internal_TemplateCompilerBase”。 I have found out that this is autoload conflict, since both my and smarty code use that. 我发现这是自动加载冲突,因为我和聪明的代码都使用了该冲突。 Here is my code: 这是我的代码:

 spl_autoload_register(array($this, 'loadClass'));

    public function loadClass($name) {
    $classes = array(
        'Config' => '../config/Config.php',
        'Error' => '../validation/Error.php',
        'Flash' => '../flash/Flash.php',
        'NotFoundException' => '../exception/NotFoundException.php',
        'TodoDao' => '../dao/TodoDao.php',
        'TodoMapper' => '../mapping/TodoMapper.php',
        'Todo' => '../model/Todo.php',
        'TodoSearchCriteria' => '../dao/TodoSearchCriteria.php',
        'TodoValidator' => '../validation/TodoValidator.php',
        'Utils' => '../util/Utils.php',
        'Smarty'=> '../smarty/libs/Smarty.class.php',
    );
    if (!array_key_exists($name, $classes)) {
        die('Class "' . $name . '" not found.');
    }
    require_once $classes[$name];
}

I am having hard time understanding what do i need to change to make this work? 我很难理解要进行这项工作需要进行哪些更改?

You should change the following code: 您应该更改以下代码:

if (!array_key_exists($name, $classes)) {
        die('Class "' . $name . '" not found.');
}
require_once $classes[$name];

into

if (array_key_exists($name, $classes)) {
        require_once $classes[$name];
}

If you stopped script when yout autoloader couldn't find class, only your autoloader is launched and if class is not found other autoloaders would not be launched to check if class exists 如果在找不到自动加载器时停止了脚本,则只会启动您的自动加载器,如果找不到该类,则不会启动其他自动加载器以检查是否存在该类

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM