Codeigniter:更新到CI4后Loader类出错



我最近将我的项目更新为CI4,还将我的WAMP更新为最新版本。

但从那以后,我的项目就没用了。application/core/中存在从CI_Controller继承的MY_Controller

它给了我这个错误:

An uncaught Exception was encountered
Type: Error
Message: The "Generator" class is reserved for internal use and cannot be manually instantiated
Filename: C:wamp64wwwalnoorsystemcoreLoader.php
Line Number: 1285
Backtrace:
File: C:wamp64wwwalnoorapplicationcoreMY_Controller.php
Line: 7
Function: __construct
File: C:wamp64wwwalnoorindex.php
Line: 315
Function: require_once

有人知道这意味着什么,或者我该如何修复它吗?

这是Loader类函数:

protected function _ci_init_library($class, $prefix, $config = FALSE, $object_name = NULL)
{
// Is there an associated config file for this class? Note: these should always be lowercase
if ($config === NULL)
{
// Fetch the config paths containing any package paths
$config_component = $this->_ci_get_component('config');
if (is_array($config_component->_config_paths))
{
$found = FALSE;
foreach ($config_component->_config_paths as $path)
{
// We test for both uppercase and lowercase, for servers that
// are case-sensitive with regard to file names. Load global first,
// override with environment next
if (file_exists($path.'config/'.strtolower($class).'.php'))
{
include($path.'config/'.strtolower($class).'.php');
$found = TRUE;
}
elseif (file_exists($path.'config/'.ucfirst(strtolower($class)).'.php'))
{
include($path.'config/'.ucfirst(strtolower($class)).'.php');
$found = TRUE;
}
if (file_exists($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php'))
{
include($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php');
$found = TRUE;
}
elseif (file_exists($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php'))
{
include($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php');
$found = TRUE;
}
// Break on the first found configuration, thus package
// files are not overridden by default paths
if ($found === TRUE)
{
break;
}
}
}
}
$class_name = $prefix.$class;
// Is the class name valid?
if ( ! class_exists($class_name, FALSE))
{
log_message('error', 'Non-existent class: '.$class_name);
show_error('Non-existent class: '.$class_name);
}
// Set the variable name we will assign the class to
// Was a custom class name supplied? If so we'll use it
if (empty($object_name))
{
$object_name = strtolower($class);
if (isset($this->_ci_varmap[$object_name]))
{
$object_name = $this->_ci_varmap[$object_name];
}
}
// Don't overwrite existing properties
$CI =& get_instance();
if (isset($CI->$object_name))
{
if ($CI->$object_name instanceof $class_name)
{
log_message('debug', $class_name." has already been instantiated as '".$object_name."'. Second attempt aborted.");
return;
}
show_error("Resource '".$object_name."' already exists and is not a ".$class_name." instance.");
}
// Save the class name and object name
$this->_ci_classes[$object_name] = $class;
// Instantiate the class
$CI->$object_name = isset($config)
? new $class_name($config)
: new $class_name();
}

错误出现在最后一条语句中。

解决方案比我想象的要简单。事实证明,CI4有一个新的内置函数Generator,在我的旧项目中,我有一个同名的库。因此,我将名称更改为My_generator,并相应地更改了代码,结果很好。

相关内容

  • 没有找到相关文章

最新更新