new controller problem

edited July 2014 in Modules
Basically want to create a controller so i can do some database queries then pass the data to view en/home, so here are the code

<?php
class En extends CI_Controller{
function En(){
parent::__construct();
}

function get_categories($category){
$query = $this->db->query("SELECT * FROM catgories WHERE category = '$category'");
return $query->result();
}

function productlist(){

$sortby=$this->input->get('some_data', TRUE);

$vars['sortby']=$sortby;
$vars['categories']=$this->get_categories($sortby);

if ($sortby) {
$query = $this->db->query("SELECT * FROM products INNER JOIN categories on products.category_id = categories.id WHERE categories.category = '$sortby'");
} else {
$query = $this->db->query("SELECT * FROM products");
}
}
}


error

Severity: Notice

Message: Undefined property: En::$db

Filename: controllers/en.php


Call to a member function query() on a non-object in /Applications/XAMPP/xamppfiles/htdocs/cms/fuel/application/controllers/en.php on line 8

how to initiate $this->db at this point??

thanks

Comments

  • edited 12:10AM
    You'll need to run $this->load->database() before calling $this->db
Sign In or Register to comment.