Welcome Guest, Not a member yet? Register   Sign In
Fatal error: Using $this when not in object context
#1

[eluser]zenixgrace[/eluser]
hi,

i'm a newbie in codeigniter

i try to make some library

i got an error like this "Fatal error: Using $this when not in object context in D:\xampp\htdocs\CI\application\bcpanel\libraries\hiemn.php on line 59"

my line 59 is "if ($where) $this->CI->db->where($where);"

my library code like that
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

echo '<pre>';

$categories = Hiemn::getTopCategories();
print_r($categories);

echo '</pre>';

class Hiemn {
    /**
     * The information stored in the database for each category
     */
    public $id;
    public $parent;
    public $name;

    // The child categories
    public $children;

// Code Igniter var instance
var $CI = NULL;

    public function __construct()
    {
  // Code Igniter get instance
  $this->CI =& get_instance();
  
        // Get the child categories when we get this category
        $this->getChildCategories();
    }

    /**
     * Get the child categories
     * @return array
     */
    public function getChildCategories()
    {
        if ($this->children) {
            return $this->children;
        }
        return $this->children = self::getCategories("parent = {$this->id}");
    }

    ////////////////////////////////////////////////////////////////////////////

    /**
     * The top-level categories (i.e. no parent)
     * @return array
     */
    public static function getTopCategories()
    {
        return self::getCategories('parent = 0');
    }

    /**
     * Get categories from the database.
     * @param string $where Conditions for the returned rows to meet
     * @return array
     */
    public static function getCategories($where = '')
    {
        if ($where) $this->CI->db->where($where);
  $query = $this->CI->db->query("SELECT * FROM msbcmn$where");

        $categories = array();
        foreach ($query->result() as $row)
  {
   $my_id = $row->KdBcMn;
   $categories['children'] = Hiemn::getCategories('parent = $my_id');
            //$categories[] = $row;
  }

        $query->free_result();
        return $categories;
    }
}
?&gt;

can someone help me to fix that out?
it's make me crazy Sad




Theme © iAndrew 2016 - Forum software by © MyBB