0

So I tried to create a library in which I can get some "global" data from one of my data tables (site name, logo, favicon, etc).

This is my current library:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Settings {
    //holds the CI instance
    //var $ci;
    protected  $ci;
    //the array the settings will be stored as
    public $settings = array();

    //
    public function __construct()
    {
        //load CI instance
        $this->ci =& get_instance();

        //fire the method loading the data
        $this->get_settings();
    }

    public function get_settings()
    {
        $this->ci->load->model('settings_model');
        $this->settings = $this->ci->Settings_model->get_list();
        return $this->settings;
    }
}
?>

This library should access to my method get_list() on my Settings_model and so far it seems to be able to do so (keep reading).

This is my settings model:

function __construct()
{
    parent::__construct();
    $this->table = 'ci_settings';
}

public function get_list()
{
    $query = $this->db->get($this->table);
    return $query->result();
}

Now to use the data which comes from the database in my views without having to declare them in all my controllers, I just have to do this(I did something similar with my menu library so I know it should work):

<?php echo $this->settings['website_name']  ?>

Here is the PROBLEM, my library is being able to access to my model which seems fine(I suppose), the problem comes when it tries to access to the get_list method itself; is apparently having some issues returning the data as this is the error that I get:

enter image description here

Should not this be possible just like this?.. what I'm trying is to have global variable for logo, website name, etc... I'm sure it should not be that hard but I'm having a really big pain in the *** trying to figure out a solution.

Any idea where is my error?, Thanks in advance.

Kirasiris
  • 523
  • 10
  • 37
  • 3
    Try with `->settings_model->` with `S` in lowercase – kip Mar 21 '18 at 19:10
  • 1
    Check line 22 in your library and use lower case for `settings_model`... – jtheman Mar 21 '18 at 19:13
  • Yeah it works now, thanks. – Kirasiris Mar 21 '18 at 19:19
  • Please close: "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers." – Alex Mar 21 '18 at 21:42
  • Yes, no problem... just tell me how to do it as I currently don't know how to "close it" . I can delete it if you want. – Kirasiris Mar 21 '18 at 21:59
  • I tried to delete it but it tells me that I cannot because people already invested their time in helping me and answering to this question. – Kirasiris Mar 21 '18 at 22:03
  • don't worry about it, didn't see the answer. as long as their is an answer whether or not it is ticked you can't delete. glad you found a solution anyways!! – Alex Mar 21 '18 at 23:14

1 Answers1

3

Try with ->settings_model-> with S in lowercase, but why ?

CI save the instance of your model internally like a property of the object CI that you have with function get_instance()

Remember: class properties are case sensitive

kip
  • 1,120
  • 7
  • 11