codeigniter 是否有 "email" 关键字?
Does codeigniter have an "email" keyword?
我收到以下错误:
An uncaught Exception was encountered
Type: RuntimeException
Message: The model name you are loading is the name of a resource that is already being used: email
但是,这里触发了错误:
if(!class_exists("email"))
{
$this->load->model("email");
}
所以它不是现有的 class,但 'email' 已被使用。 'email' 是 codeigniter 中的关键字吗?如果不是,我如何找出触发此错误的原因?
这是 CI 中的缺陷之一 - 因为它使用自己的超全局对象来保存任何已加载的库、模型和第三方库。
if you take a look at the Loader Class here you see that Codeigniter checks if the name is already used and therefore reserved.
简而言之:
您的问题是,您已经加载了 email
库,这意味着您不能再使用它的名称了。
由于 Codeigniter 并不真正支持命名空间,因此您必须找到另一种技术来避免命名冲突。
我建议使用严格的命名约定。
例如:
- 对于任何模型,您都应该使用
_model
后缀。
- 对于任何自制的库,
_library
后缀。
在您的具体情况下,只需将您的 Email
模型重命名为 Email_model
。
For more informations how to load a model please look at their documentation.
我收到以下错误:
An uncaught Exception was encountered
Type: RuntimeException
Message: The model name you are loading is the name of a resource that is already being used: email
但是,这里触发了错误:
if(!class_exists("email"))
{
$this->load->model("email");
}
所以它不是现有的 class,但 'email' 已被使用。 'email' 是 codeigniter 中的关键字吗?如果不是,我如何找出触发此错误的原因?
这是 CI 中的缺陷之一 - 因为它使用自己的超全局对象来保存任何已加载的库、模型和第三方库。
if you take a look at the Loader Class here you see that Codeigniter checks if the name is already used and therefore reserved.
简而言之:
您的问题是,您已经加载了 email
库,这意味着您不能再使用它的名称了。
由于 Codeigniter 并不真正支持命名空间,因此您必须找到另一种技术来避免命名冲突。 我建议使用严格的命名约定。
例如:
- 对于任何模型,您都应该使用
_model
后缀。 - 对于任何自制的库,
_library
后缀。
在您的具体情况下,只需将您的 Email
模型重命名为 Email_model
。
For more informations how to load a model please look at their documentation.