通过静态方法使用CodeIgniter库

Chr*_*gar 0 php codeigniter

我在我的静态函数中尝试调用CodeIgniter方法时遇到了麻烦,只是使用$这不起作用,因为它不在对象上下文中,静态关键字也不起作用.这是我的核心模型中的代码示例,$ table变量是从另一个模型(如posts)成功定义的.

class MY_Model extends CI_Model {

    protected static $table;

    public function __construct() {
        parent::__construct();
    }

    public static function find_all() {
        $this->db->select('*');
        $sql = $this->db->get(static::$table);
        return $sql->result();
    }

}
Run Code Online (Sandbox Code Playgroud)

fil*_*lip 5

如果$ this不起作用,你可以像这样解决这个问题:

$CI =& get_instance();
$CI->db->...