このエラーを見て、私はあまりにも長い間髪を引っ張ってきました。私は 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 関数を呼び出そうとしています。誰かが私が間違っていることを見ることができますか?