Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeigniter - Call to a member function on a non-object
    primarykey
    data
    text
    <p>I have been pulling my hair out for too long looking at this error. I am using Codeigniter 2 and have created MY_Controller class to load a few settings into my session data.</p> <p>Which you can see below:</p> <pre><code>class MY_Controller extends CI_Controller { protected $ajax = 0; public function __construct() { parent::__construct(); $this-&gt;load-&gt;model('settings_model'); //is the session user agent set if ($this-&gt;session-&gt;userdata('browser') == false) { $this-&gt;load-&gt;library('user_agent'); $this-&gt;session-&gt;set_userdata(array( 'browser' =&gt; $this-&gt;agent-&gt;browser(), 'browser_version' =&gt; $this-&gt;agent-&gt;version(), 'is_mobile' =&gt; $this-&gt;agent-&gt;is_mobile() ? 1 : 0 )); } //is the settings loaded if ($this-&gt;session-&gt;userdata('league_name') == false) { $this-&gt;Settings_model-&gt;get_general_settings(); } //get the menu if we need to //if ($this-&gt;session-&gt;userdata('menu') == false) //$this-&gt;Settings_model-&gt;get_menu_items(); //set the main part of the title $this-&gt;set_title($this-&gt;session-&gt;userdata('league_name')); //get that referring url $this-&gt;session-&gt;set_userdata('refered_from', isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : base_url()); //ajax request $this-&gt;ajax = isset($_GET['ajax']) ? 1 : 0; } } </code></pre> <p>Where I am running into the problem is I keep getting this error:</p> <pre><code>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 </code></pre> <p>Here is the Settings_model.php file that I am loading, yes it is in my application/models folder:</p> <pre><code>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-&gt;db-&gt;query($query); foreach ($result-&gt;result_array() as $row) $this-&gt;session-&gt;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-&gt;db-&gt;query($query); foreach ($result-&gt;result_array() as $row) $this-&gt;session-&gt;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-&gt;db-&gt;query($query); foreach ($result-&gt;result_array() as $row) $this-&gt;session-&gt;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-&gt;db-&gt;query($query); foreach ($result-&gt;result_array() as $row) $this-&gt;session-&gt;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-&gt;db-&gt;query($query); foreach ($result-&gt;result_array() as $row) $items[$row['menu_id']] = $row; $this-&gt;session-&gt;set_userdata('menu', $items); } } </code></pre> <p>I am trying to call the get_general_settings function. Can anyone see what I am doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload