Php CodeIgniter:堆芯/覆盖,缺少装载机/装载机类别
好吧,我有这个问题,谷歌没有帮助,我想这是因为我的问题太简单了 我正在尝试Php CodeIgniter:堆芯/覆盖,缺少装载机/装载机类别,php,codeigniter,Php,Codeigniter,好吧,我有这个问题,谷歌没有帮助,我想这是因为我的问题太简单了 我正在尝试load任何东西,或者连接load->database()但它不工作 这是我的代码和注释,它将解释一切 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class CI_Lang { function __construct() { # Show all files included
load
任何东西,或者连接load->database()代码>但它不工作
这是我的代码和注释,它将解释一切
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class CI_Lang {
function __construct() {
# Show all files included
print_r(get_included_files()); // There is nothing like loader or load .php
# Check for loader file
if( ! class_exists('loader') || ! class_exists('load')) {
echo 'no load '; // is being shown,
}
# Check Database connection before
if (isset($this->db->conn_id) && is_resource($this->db->conn_id)) {
echo 'database is loaded and conected ';
} else {
echo 'no connection '; // is being shown,
}
# Get Database connection
$this->load->library('database');
/*
Script dies on line above with error:
Fatal error: Call to a member function library() on a non-object in
application/core/Lang.php on line 38
*/
$this->load->database();
# Check Database connection after
if (isset($this->db->conn_id) && is_resource($this->db->conn_id)) {
echo 'database is loaded and conected ';
} else {
echo 'no connection ';
}
# Register as loaded
log_message('debug', 'JK_Lang Class initialized');
}
}
现在我已经没有主意了,有什么帮助吗?问题是,我没有声明codeigniter实例。所以有两种方法来修复它
首先,我可以创建一个函数,如:
function __construct() {
$this->run();
}
function run() {
/* All my __construct code here */
}
或者,在我实际解决问题时,我创建了一个库,为了获得使用codeigniter所需的所有东西,我创建了一个实例:
class L {
var $CI;
function __construct() {
$this->CI =& get_instance();
$this->CI->load->database();
$this->test();
}
function test() {
$query = $this->CI->db->query("SELECT * FROM `stackoverflow.com`");
}
}
为什么我会被降级/否决,我的问题有什么问题我应该知道吗?请告诉我。
class L {
var $CI;
function __construct() {
$this->CI =& get_instance();
$this->CI->load->database();
$this->test();
}
function test() {
$query = $this->CI->db->query("SELECT * FROM `stackoverflow.com`");
}
}