【发布时间】:2014-03-14 16:28:21
【问题描述】:
我一直在为已移植到 CI 框架的项目创建自定义库,但遇到了某些类具有相同名称的问题。
为了规避这个问题,我尝试实现命名空间无济于事。我一直在做研究,我知道过去这可能是不可能的,但是对于较新版本的 PHP,我想知道是否有办法做到这一点,或者我是否做得正确。
CI 版本:2.1.4 PHP版本:5.4.12
这是我的设置演示:
应用程序/库/class1.php
<?
class class1{
public function __construct()
{
$CI =& get_instance();
$CI->load->library('foo/class2.php');
}
}
?>
application/libraries/foo/class2.php
<?
namespace foo
class class2{
function bar(){
}
}
?>
当我运行我的 CI 应用程序时,我会收到以下错误:
不存在的类:class2
感谢您的帮助。
【问题讨论】:
-
我在github上快速搜索了github.com/EllisLab/CodeIgniter/issues/2820
-
在 CI index.php 中使用 composer/PSR-0 并要求 composer 自动加载。我通过这种方法使用“哎呀”和“独白”!
-
Alex 写了一个对我有用的答案。 Here's the answer.
标签: php codeigniter namespaces