1.models/calists.php // model file model file here category list database controller
<?php if ( ! defined('basepath')) exit('no direct script access allowed'); class catlists extends ci_model { public function __construct() { $this->load->database(); //load database } public function getcategories() { $query = $this->db->get_where('category',array('status'=>'enable')); if ($query->num_rows() > 0) { return $query->result(); } else { return array(); } } } ?>
2.controllers/catlist.php // controller file controller data model
<?php if ( ! defined('basepath')) exit('no direct script access allowed'); class catlist extends ci_controller { public function __construct() { parent::__construct(); $this->load->model('catlists'); } public function catlist() { $data['catlist'] = $this->catlists->getcategories(); $this->load->view('home', $data); } }
in header printng categories list
print_r($data['catlist']);
i not sure error getting here, when loading model in controller, first letter should capital.
$this->load->model('catlists'); $data['catlist'] = $this->catlists->getcategories();
in header have call
print_r($catlist);
Comments
Post a Comment