0

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
  • As told you in your other question, DB should go into the MODEL. WHY does this really need to be into an helper? why not a library? a model? a driver? Anyway, HELPERS are NOT CLASSES. For this question and other Qs of yours I saw before, I suggest you take a small break and start reading the (great) CI's documentation; many of your question would be avoided/answered just by having a general better understanding of how CI works. CI's one of the best documented framework out there, take advantage of this! Mar 6, 2012 at 10:51

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.