CodeIgniter:无法在函数内访问$ this

|| 我正在使用CodeIgniter,我的视图之一很大,因此我将某些代码移到了同一文件中的函数中:
function html_stuff()
{
    $posts = $this->db->query(\'select * from posts\');
}
当我运行此代码时,出现以下错误:   致命错误:不在时使用$ this   /somepath/view.php中的对象上下文     
已邀请:
        您可以传递函数
$this
function html_stuff($ci) {
    $ci->db->query(\'select * from posts\');
}
html_stuff($this);
或者用use3ѭ
function html_stuff() {
    $ci = &get_instance();
    $ci->db->query(\'select * from posts\');
}
请参阅:https://www.codeigniter.com/user_guide/general/creating_libraries.html     

要回复问题请先登录注册