Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all articles
Browse latest Browse all 14343

Library not working

$
0
0
I tried to implement a library which allows me to display global data like site name, site logo, etc from the database to all the views without the necessity of passing them via controllers(which I think is time consuming).


PHP Code:
<?php

class Settings {
 
   //holds the CI instance
 
   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');
 
       $settings $this->ci->Settings_model->get_list();
 
       return $settings;
 
   }
}
?>


now in order to put it in my views, I've gotten to do just this:

PHP Code:
<?php echo $settings['website_name' ?>

This is what I get, two errors, one for the undefined property:


Quote:Severity: Notice
Message: Undefined property: Store::$settings_model
Filename: libraries/Settings.php
Line Number: 22
Backtrace:
File: C:\xampp\htdocs\codeigniter\app\libraries\Settings.php
Line: 22
Function: _error_handler

File: C:\xampp\htdocs\codeigniter\app\libraries\Settings.php
Line: 17
Function: get_settings

File: C:\xampp\htdocs\codeigniter\app\core\MY_Controller.php
Line: 8
Function: __construct

File: C:\xampp\htdocs\codeigniter\app\core\MY_Controller.php
Line: 34
Function: __construct

File: C:\xampp\htdocs\codeigniter\index.php
Line: 315
Function: require_once

and one for the function calling in null(is there a way to overwrite this?):
Quote:An uncaught Exception was encountered
Type: Error
Message: Call to a member function get_list() on null
Filename: C:\xampp\htdocs\codeigniter\app\libraries\Settings.php
Line Number: 22
Backtrace:
File: C:\xampp\htdocs\codeigniter\app\libraries\Settings.php
Line: 17
Function: get_settings

File: C:\xampp\htdocs\codeigniter\app\core\MY_Controller.php
Line: 8
Function: __construct

File: C:\xampp\htdocs\codeigniter\app\core\MY_Controller.php
Line: 34
Function: __construct

File: C:\xampp\htdocs\codeigniter\index.php
Line: 315
Function: require_once


I hope I could make myself clear.

Thanks in advance.

Viewing all articles
Browse latest Browse all 14343

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>