CodeIgniter + Eclipse: Class 'Controller' and 'Model' not found

Home Forums Programming PHP & MySQL CodeIgniter + Eclipse: Class 'Controller' and 'Model' not found

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1724
    Satish
    Keymaster

    Error

    Fatal error: Class 'Controller' not found in C:\wamp\www\CI\application\controllers\site.php on line 2

    and


    Fatal error: Class 'Model' not found in C:\wamp\www\CI\application\models\site_model.php on line 2

    Solution:
    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);
     }
     }
    ?>
    
    #1726
    Satish
    Keymaster

    bbc is table name!

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.