我已经开始使用 CodeIgniter,但我无法理解一个想法。如何将一个类加载到另一个类中?
$this->load->library("hello_world");
这不起作用?
我的类 -> 加载 -> hello_world 类
class myclass {
function test() {
$this->load->library("hello_world");
$this->hello_world->hello();
}
}
消息:未定义的属性:myclass::$load
最佳答案
加载类的能力取决于可用的加载->库函数。它可供 Controller 和模型类使用,但扩展它们可能不适合您的使用。
相反,您可以获取对 CI 的引用并使用它来加载和引用您的类,也可以像往常一样在 PHP 中加载它($c = new MyClass)。
要获得 CI 引用,请使用以下命令:
$CI =& get_instance();
$CI->load->helper('url');
$CI->load->library('session');
$CI->config->item('base_url');
etc.
关于php - CodeIgniter将类加载到类中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2981817/