CodeIgniter Forums
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 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- 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 (/showthread.php?tid=43121)

Pages: 1 2


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 - El Forum - 06-30-2011

[eluser]fancy_stuff[/eluser]
Hello,

I just downloaded a CodeIgniter2.0.2, but I found the application folder is not under system folder, then I found some error when I using the model (classes) in my controllers. I doubt if that is because the folder changing in 2.0.2 version. (in the 1.7 version, the application folder is under system folder.)

Please help.

Thanks

Fancy


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 - El Forum - 06-30-2011

[eluser]CodeIgniteMe[/eluser]
That is because CodeIgniter 1.7+ still supports backward compatibility for PHP4, please update your codes from
Code:
Class Myclass extends Model
{
function Myclass()
{
parent::Model();
}
}
to
Code:
Class Myclass extends CI_Model
{
function __construct()
{
parent::__construct();
}
}
this also applies to all your controllers.


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 - El Forum - 06-30-2011

[eluser]InsiteFX[/eluser]
Also Controller is now CI_Controller

As far as the application folder there is no changes it was moved out because everyone always moved it out when it was under the system folder.

InsiteFX


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 - El Forum - 06-30-2011

[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


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 - El Forum - 06-30-2011

[eluser]InsiteFX[/eluser]
You have an error here <&lt;html &gt; should be &lt;html&gt;

Did you save all your Models with lowercase filenames?

Fatal error: Class 'Mcats' not found in C:\xampp\htdocs\ci_sample\system\core\Loader.php on line 188
MCats |

InsiteFX


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 - El Forum - 06-30-2011

[eluser]fancy_stuff[/eluser]
Thanks, InsiteFX.

I fixed the typo thing. and also checked the file name, all with lower case.

mcats.php in model folder
mproducts.php in model folder

welcome.php in controller folder
template.php in view folder.

error is still there.

Thanks for help, please.


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 - El Forum - 06-30-2011

[eluser]CodeIgniteMe[/eluser]
You forgot something in your Controller:
Code:
public function index()
  {
      $data[‘title’]=“Welcome to Claudia’s Kids”;
      $this->load->model('mcats','MCats'); // add this line
      // I added MCats in the second parameter if you want to use MCats in this case
      $data[‘navlist’] = $this->MCats->getAllCategories();
      $this->load->vars($data);
      $this->load->view(‘template’);
  
  }



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 - El Forum - 06-30-2011

[eluser]fancy_stuff[/eluser]
Hi there.

I already used $autoload['model'] = array('MCats','MProducts'); in autoload.php

I tried with your way to add $this->load->model('mcats','MCats'); in the function index(). But it just the same thing, the error is not gone.

Please advise, thanks


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 - El Forum - 06-30-2011

[eluser]CodeIgniteMe[/eluser]
[quote author="fancy_stuff" date="1309515913"]Hi there.
I already used $autoload['model'] = array('MCats','MProducts'); in autoload.php
[/quote]

Try changing MCats and MProducts to lower case characters.


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 - El Forum - 07-01-2011

[eluser]fancy_stuff[/eluser]
Still the same thing, same error. Thanks