dougang5993 2012-03-06 10:39
浏览 62
已采纳

创建帮助程序 - >在非对象上调用成员函数get()

I try to create my own helper but face a problem.

First i create a function called select. First if you see something wrong in this method pls tell me.

public function select($where = null, $order = null, $limit = null, $columns = '*') {
        if (!$columns)
            $this->db->select('*');
        elseif (is_array($columns)) {
            $columns = implode(',', $columns);
            $this->db->select($columns);
        }

        if ($where)
            $this->db->where($where);
        if ($order)
            $this->db->order_by($order);
        if ($limit)
            $this->db->limit($limit);

        $query  = $this->db->get('pasaj_register');

        return $query;
    }

and then i try to call this function like that

pasajItem  = new pasajItem();
         $a = $pasajItem->select();
         echo $a;

However i take this error: enter image description here

  • 写回答

1条回答 默认 最新

  • dongnue2071 2012-03-06 10:55
    关注

    Within a helper you cannot acces the database. First of all, it's not intended to do so. You'll probably want to make a library of this, where you give a reference to the database on creation.

    Besides the design flaw i believe you are making here, you have to use:

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

    to access the CodeIgniter Database from a helper or library. This is because they don't derive form a CodeIgniter standard class which contains the objects.

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

报告相同问题?

悬赏问题

  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法