Welcome Guest, Not a member yet? Register   Sign In
Why the application folder is not within system folder in CI 2.0.2 ? Does that matters for the path of the programs in C
#4

[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">
<&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;&lt;?php echo $title;?&gt;&lt;/title&gt;
&lt;link href="&lt;?=base_url();?&gt;css/default.css" rel="stylesheet" type="text/css" /&gt;
[removed]
//&lt;![CDATA[
base_url = '&lt;?=base_url();?&gt;';
//]]>
[removed]
&lt;/head&gt;

&lt;body&gt;
<div id="wrapper">
<div id="header">
&lt;?php $this->load->view('header');
</div>

<div id="nav">
&lt;?php $this->load->view('navigation');
</div>

<div id="main">
&lt;?php $this->load->view('main');
</div>

<div id="footer">
&lt;?php $this->load->view('footer');
</div>
</div>
&lt;/body&gt;
&lt;/html&gt;

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


Messages In This Thread
Why the application folder is not within system folder in CI 2.0.2 ? Does that matters for the path of the programs in C - by El Forum - 06-30-2011, 10:20 PM



Theme © iAndrew 2016 - Forum software by © MyBB