Welcome Guest, Not a member yet? Register   Sign In
loading model result error
#1

[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
#2

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

[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');
    }
}
#4

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

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

[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;
        }    
    }
#7

[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.
#8

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

<php
class Site_model extends CI_Model {

must have &lt;?php



najam is great
#9

[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
#10

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




Theme © iAndrew 2016 - Forum software by © MyBB