CodeIgniter Forums
loading model result error - 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: loading model result error (/showthread.php?tid=38805)

Pages: 1 2


loading model result error - El Forum - 02-19-2011

[eluser]roothacker[/eluser]
hi i m new to codeigniter and I just start playing it i have downloaded version 2.0 and only set config.php,database.php,autoload.php for database settings and loading database library.
Then I have created a controller name site.php and then created a model "site_model.php"
inside this file declare a class as follows
Code:
<php
class Site_model extends CI_Model {

    function __construct()
    {
        parent::__construct();
    }
    function GetAll()
    {
        $query = $this->db->get('test', 10);
        return $query->result();
    }
}

?&gt;


now inside my controller "site.php" I have following code
Code:
&lt;?php
class site extends CI_Controller
{
    function index()
    {
        $this->load->model('Site_model');
        $this->load->view('home');
    }
    function about()
    {
        $this->load->view('about');
    }
}

Now as i open site in browser giving me following error

Code:
db->get('test', 10); return $query->result(); } } ?&gt;
( ! ) Fatal error: Class 'Site_model' not found in D:\wamp\www\ci\system\core\Loader.php on line 198
Call Stack
#    Time    Memory    Function    Location
1    0.0008    688848    {main}( )    ..\index.php:0
2    0.0025    760392    require_once( 'D:\wamp\www\ci\system\core\CodeIgniter.php' )    ..\index.php:163
3    0.0415    3317328    call_user_func_array ( )    ..\CodeIgniter.php:297
4    0.0415    3317408    site->index( )    ..\CodeIgniter.php:0
5    0.0415    3317536    CI_Loader->model( )    ..\site.php:6



loading model result error - El Forum - 02-19-2011

[eluser]mariuskmc[/eluser]
sorry .... wrong answer ... but I could not delete update post


loading model result error - El Forum - 02-19-2011

[eluser]roothacker[/eluser]
[quote author="mariuskmc" date="1298133009"]In controler mast have

Code:
function __construct()
    {
        parent::__construct();
    }
[/quote]


still not working
Code:
&lt;?php
class site extends CI_Controller
{
function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        $this->load->model('Site_model');
        $this->load->view('home');
    }
    function about()
    {
        $this->load->view('about');
    }
}



loading model result error - El Forum - 02-19-2011

[eluser]roothacker[/eluser]
i also want to post all of my code is it allowed?


loading model result error - El Forum - 02-19-2011

[eluser]mariuskmc[/eluser]
send to PM maybe I can help


loading model result error - El Forum - 02-19-2011

[eluser]mariuskmc[/eluser]
Code:
function getAll() {
        $this->db->select('test.* ');
        $this->db->from('test');
                $this->db->limit('10');    
        $q = $this->db->get();
        
        if($q->num_rows() > 0) {
            foreach ($q->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }    
    }



loading model result error - El Forum - 02-19-2011

[eluser]roothacker[/eluser]
I have uploaded my source code at http://www.box.net/shared/xnejcl0oxo

Please download and find out whats wrong in it.


loading model result error - El Forum - 02-19-2011

[eluser]mariuskmc[/eluser]
in model you start with

<php
class Site_model extends CI_Model {

must have &lt;?php



najam is great


loading model result error - El Forum - 02-19-2011

[eluser]roothacker[/eluser]
[quote author="mariuskmc" date="1298137014"]
Code:
function getAll() {
        $this->db->select('test.* ');
        $this->db->from('test');
                $this->db->limit('10');    
        $q = $this->db->get();
        
        if($q->num_rows() > 0) {
            foreach ($q->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }    
    }
[/quote]


I think error was related to some loader class that cant load my model
Fatal error: Class 'Site_model' not found in D:\wamp\www\ci\system\core\Loader.php on line 198


loading model result error - El Forum - 02-19-2011

[eluser]mariuskmc[/eluser]
must have &lt;?php in model