dsk88199 2018-03-21 18:57
浏览 63
已采纳

库不在CodeIgniter上工作

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.

  • 写回答

1条回答 默认 最新

  • douzhangli9563 2018-03-21 19:22
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
  • ¥15 stm32的can接口不能收发数据
  • ¥15 目标检测算法移植到arm开发板
  • ¥15 利用JD51设计温度报警系统
  • ¥15 快手联盟怎么快速的跑出建立模型