看着这个错误,我已经把头发拉出来太久了。我正在使用 Codeigniter 2 并创建了 MY_Controller 类来将一些设置加载到我的会话数据中。
您可以在下面看到:
class MY_Controller extends CI_Controller {
protected $ajax = 0;
public function __construct() {
parent::__construct();
$this->load->model('settings_model');
//is the session user agent set
if ($this->session->userdata('browser') == false)
{
$this->load->library('user_agent');
$this->session->set_userdata(array(
'browser' => $this->agent->browser(),
'browser_version' => $this->agent->version(),
'is_mobile' => $this->agent->is_mobile() ? 1 : 0
));
}
//is the settings loaded
if ($this->session->userdata('league_name') == false)
{
$this->Settings_model->get_general_settings();
}
//get the menu if we need to
//if ($this->session->userdata('menu') == false)
//$this->Settings_model->get_menu_items();
//set the main part of the title
$this->set_title($this->session->userdata('league_name'));
//get that referring url
$this->session->set_userdata('refered_from', isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : base_url());
//ajax request
$this->ajax = isset($_GET['ajax']) ? 1 : 0;
}
}
我遇到问题的地方是我不断收到此错误:
Fatal error: Call to a member function get_general_settings() on a non-object in C:\xampp\htdocs\osmdev\application\controllers\welcome.php on line 12
这是我正在加载的 Settings_model.php 文件,是的,它位于我的 application/models 文件夹中:
class Settings_model extends CI_Model
{
// Call the Model constructor
function __construct() {
parent::__construct();
}
//get the general settings
function get_general_settings() {
$query = "SELECT setting_id, variable, value FROM settings WHERE non_session = 0";
$result = $this->db->query($query);
foreach ($result->result_array() as $row)
$this->session->set_userdata($row['variable'], stripslashes($row['value']));
}
//get all the settings we have
function get_all_settings() {
$query = "SELECT setting_id, variable, value FROM settings";
$result = $this->db->query($query);
foreach ($result->result_array() as $row)
$this->session->set_userdata($row['variable'], stripslashes($row['value']));
}
//get a specfic setting variable
function get_specific_setting($var) {
$query = "SELECT setting_id, variable, value FROM settings WHERE variable = '".$var;
$result = $this->db->query($query);
foreach ($result->result_array() as $row)
$this->session->set_userdata($row['variable'], stripslashes($row['value']));
}
//get a specific type of setting
function get_type_setting($type) {
$query = "SELECT setting_id, variable, value FROM settings WHERE action = '".$type;
$result = $this->db->query($query);
foreach ($result->result_array() as $row)
$this->session->set_userdata($row['variable'], stripslashes($row['value']));
}
//get all the menu items
function get_menu_items($type=0) {
$query = "SELECT menu_id, title, menu_url, parent_id, level, function_used, perm_id, icon FROM menu WHERE active = 1 AND is_admin_menu = '".$type;
$result = $this->db->query($query);
foreach ($result->result_array() as $row)
$items[$row['menu_id']] = $row;
$this->session->set_userdata('menu', $items);
}
}
我正在尝试调用 get_general_settings 函数。谁能看到我做错了什么?