Home › Forums › Programming › PHP & MySQL › CodeIgniter + Eclipse: Class 'Controller' and 'Model' not found
Tagged: class not found, codeigniter, controller, eclipse, model
- This topic has 1 reply, 1 voice, and was last updated 12 years, 3 months ago by Satish.
Viewing 2 posts - 1 through 2 (of 2 total)
- AuthorPosts
- July 24, 2012 at 8:16 pm#1724SatishKeymaster
Error
Fatal error: Class 'Controller' not found in C:\wamp\www\CI\application\controllers\site.php on line 2and
Fatal error: Class 'Model' not found in C:\wamp\www\CI\application\models\site_model.php on line 2Solution:
Under models -> site_model.php<?php class Site_model extends Model { function getAll(){ $q = $this->db->get('bbc'); if( $q->num_rows() > 0 ) { foreach($q->result() as $row) $data[] = $row; return $data; } } } ?>
Under controllers -> site.php
<?php class Site extends Controller { function index() { $this->load->model('site_model'); $data['records'] = $this->site_model->getAll(); $this->load->view('home',$data); } } ?>
In both the cases, add CI_ to Model and Controller
i.e., CI_Model and CI_Controller
Under models -> site_model.php
<?php class Site_model extends CI_Model { function getAll(){ $q = $this->db->get('bbc'); if( $q->num_rows() > 0 ) { foreach($q->result() as $row) $data[] = $row; return $data; } } } ?>
Under controllers -> site.php
<?php class Site extends CI_Controller { function index() { $this->load->model('site_model'); $data['records'] = $this->site_model->getAll(); $this->load->view('home',$data); } } ?>
July 24, 2012 at 8:25 pm#1726SatishKeymasterbbc is table name!
- AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.