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 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看