[eluser]fancy_stuff[/eluser]
Thanks for the replies.
I did use right syntax such as CI_Controller, CI_Model, also __construct().
MCats Model:
class MCats extends CI_Model {
function __construct() {
parent::__construct();
}
function getCategory($id){
$data = array();
$options = array('id'=> $id);
//this function passes in an $id variable that is used to select one (and only one) row matching
//that id from the categories table. It then returns the data as an array for future use.
$Q = $this->db->get_where('categories', $options, 1);
if($Q->row_array() >0){
$data = $Q->row_array();
}
$Q->free_result();
return $data;
}
function getAllCategories(){
$data = array();
$Q = $this->db->get('categories');
if($Q->num_rows()>0){
foreach ($Q->result_array()as $row){
$data[] = $row;
}
}
$Q->free_result();
return $data;
}
}
MProducts Model:
class MProducts extends CI_Model {
function __construct() {
parent::__construct();
}
function getProduct($id){
$data = array();
$options = array('id'=> $id);
//this function passes in an $id variable that is used to select one (and only one) row matching
//that id from the products table. It then returns the data as an array for future use.
$Q = $this->db->get_where('products', $options, 1);
if($Q->row_array() >0){
$data = $Q->row_array();
}
$Q->free_result();
return $data;
}
function getAllProducts(){
$data = array();
$Q = $this->db->get('products');
if($Q->num_rows()>0){
foreach ($Q->result_array()as $row){
$data[] = $row;
}
}
$Q->free_result();
return $data;
}
}
Welcome controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
function __construct(){
parent::__construct();
}
public function index()
{
$data['title']="Welcome to Claudia's Kids";
$data['navlist'] = $this->MCats->getAllCategories();
$this->load->vars($data);
$this->load->view('template');
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
View:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<<html >
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title><?php echo $title;?></title>
<link href="<?=base_url();?>css/default.css" rel="stylesheet" type="text/css" />
[removed]
//<![CDATA[
base_url = '<?=base_url();?>';
//]]>
[removed]
</head>
<body>
<div id="wrapper">
<div id="header">
<?php $this->load->view('header');
</div>
<div id="nav">
<?php $this->load->view('navigation');
</div>
<div id="main">
<?php $this->load->view('main');
</div>
<div id="footer">
<?php $this->load->view('footer');
</div>
</div>
</body>
</html>
Here is the error:
class MCats extends CI_Model { function __construct() { parent::__construct(); } function getCategory($id){ $data = array(); $options = array('id'=> $id); //this function passes in an $id variable that is used to select one (and only one) row matching //that id from the categories table. It then returns the data as an array for future use. $Q = $this->db->get_where('categories', $options, 1); if($Q->row_array() >0){ $data = $Q->row_array(); } $Q->free_result(); return $data; } function getAllCategories(){ $data = array(); $Q = $this->db->get('categories'); if($Q->num_rows()>0){ foreach ($Q->result_array()as $row){ $data[] = $row; } } $Q->free_result(); return $data; } }
Fatal error: Class 'Mcats' not found in C:\xampp\htdocs\ci_sample\system\core\Loader.php on line 188
Can anyone tell me what's wrong with the code. I also did "$autoload['model'] = array('MCats','MProducts');" in autoload.php.
Thanks