[SOLVED]Model problem - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: [SOLVED]Model problem (/showthread.php?tid=33596) |
[SOLVED]Model problem - El Forum - 09-01-2010 [eluser]Redwhirl[/eluser] Hi, I am starting with CI, and I already have a problem Here is my site controller code class Home extends Controller{ function index() { $this->load->model('Data_model'); $data['records']=$this->data_model->getall(); $this->load->view('main_view',$data); } } My Data_Model code is <? php class Data_model extends Model { function Data_model() { parent::Model(); } function index() { // Accessing database } } ?> when I run the code, here is what I get db->get('raflist'); if ($q_all->num_rows > 0) { foreach ($q_all->result() as $row) { $data[] = $row->prod_name; $data[] = $row->nb_tickets_sold; $data[] = $row->bin_price.$row->end_date; } $q_all->free_result(); return $data; } } } } ?> Fatal error: Class 'Data_model' not found in C:\WampServer\www\Rafflz\system\libraries\Loader.php on line 184 The model Data_model is in the models folder and seems to be declared properly, but I can't seem to find what the error is Help please Hubert [SOLVED]Model problem - El Forum - 09-01-2010 [eluser]Geo Paul[/eluser] Try changing all the 'D' of you Data_model to 'd' .. so it will be data_model.php class data_model{} $this->load->model('data_model'); $this->data_model->function(); I once had such a problem which was solved like this! [SOLVED]Model problem - El Forum - 09-01-2010 [eluser]Geo Paul[/eluser] And Please make sure to add parent::Controller(); to the controller Constructor!!.. //php 5 constructor function __construct() { parent::Controller(); } //php 4 constructor function user_controller() { parent::Controller(); } [SOLVED]Model problem - El Forum - 09-01-2010 [eluser]Redwhirl[/eluser] Hi, Thanks for the answers. I did what you suggested but nothing changed, I still have the error. Hubert [SOLVED]Model problem - El Forum - 09-01-2010 [eluser]danmontgomery[/eluser] You're getting PHP code as part of your error message? [SOLVED]Model problem - El Forum - 09-01-2010 [eluser]Redwhirl[/eluser] Hi, I only get this error message db->get(‘raflist’); if ($q_all->num_rows > 0) { foreach ($q_all->result() as $row) { $data[] = $row->prod_name; $data[] = $row->nb_tickets_sold; $data[] = $row->bin_price.$row->end_date; } $q_all->free_result(); return $data; } } } } ?> Fatal error: Class ‘Data_model’ not found in C:\WampServer\www\Rafflz\system\libraries\Loader.php on line 184 Thanks [SOLVED]Model problem - El Forum - 09-01-2010 [eluser]Redwhirl[/eluser] Hi the php code that appears in the message is part of the Data_model model Here is the code <? php class Data_model extends Model { // function data_model() function __construct() { parent::Controller(); } //php 4 constructor function user_controller() { parent::Controller(); } // { // parent::Model(); // } function index() { function getall(){ $q_all = $this->db->get('raflist'); if ($q_all->num_rows > 0) { foreach ($q_all->result() as $row) { $data[] = $row->prod_name; $data[] = $row->nb_tickets_sold; $data[] = $row->bin_price.$row->end_date; } $q_all->free_result(); return $data; } } } } ?> [SOLVED]Model problem - El Forum - 09-01-2010 [eluser]kaejiavo[/eluser] your model code is a complete mess. try this cleaned up code: Code: class Data_model extends Model { the file must be in the models directory, named as data_model.php your Controller: Code: class Home extends Controller{ When you changed this, y [SOLVED]Model problem - El Forum - 09-01-2010 [eluser]Redwhirl[/eluser] Thanks for your help, I have made the changes you gave me, it's going better, but I still have this db->get('raflist'); if (!$q_all->num_rows) { return FALSE; } return result_array(); } // End of function getall } // End of class Fatal error: Class 'Data_model' not found in C:\WampServer\www\Rafflz\system\libraries\Loader.php on line 184 Data_model.php is in the models directory Probably something stupid hanging [SOLVED]Model problem - El Forum - 09-01-2010 [eluser]kaejiavo[/eluser] data_model.php must be written in lower case as filename and please correct the constructor function data_model() to function Data_model() |