CodeIgniter Forums
Fatal error: Class 'Test_model' not found... - 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: Fatal error: Class 'Test_model' not found... (/showthread.php?tid=7093)



Fatal error: Class 'Test_model' not found... - El Forum - 03-24-2008

[eluser]Gary the Llama[/eluser]
Brand new to CI and I've been going through the User Guide. Everything was great until I got to the Models section.

Here's my model code which is in application/models/test.php:

Code:
class test extends Model
{
    function test()
    {
        // Call the Model constructor.
        parent::Model();
    }
}

I call it from application/controllers/mytest.php like so:

Code:
function index()
{
       $this->load->database();
       $this->load->model('test');

}

And when I go to the page I get this error:

Fatal error: Class 'test' not found in /nfsn/content/garythellama/public/system/libraries/Loader.php on line 177

Any ideas? I saw that there were issues with the class names of your model so I've tried every possible variation and it hasn't made a difference.


Fatal error: Class 'Test_model' not found... - El Forum - 03-24-2008

[eluser]Armchair Samurai[/eluser]
Direct from the User Guide:
Quote:Class names must have the first letter capitalized with the rest of the name lowercase.
Depending on what system you're running, text might be case sensitive - try capitalizing your class name and constructor.


Fatal error: Class 'Test_model' not found... - El Forum - 03-24-2008

[eluser]Gary the Llama[/eluser]
Yeah, I've tried that too. No luck. Same error.


Fatal error: Class 'Test_model' not found... - El Forum - 03-24-2008

[eluser]nirbhab[/eluser]
Use <?php ?> rather than <? ?>,
is there any directory or controller or library named test? I mean, is there any other class test in controller or owner library.

finally, try this:
Code:
class testing extends Model
{
    function testing()
    {
        // Call the Model constructor.
        parent::Model();
    }
}

//controller
function index()
{
       $this->load->database();
       $this->load->model('testing');

}
Hope your file named test/testing exists in Models directory and class name and filenames are same.


Fatal error: Class 'Test_model' not found... - El Forum - 03-24-2008

[eluser]wiredesignz[/eluser]
The error suggests the loader has found and loaded the test.php file, but it can't find the class.
Code:
//CI_Loader.php line 173
require_once(APPPATH.'models/'.$path.$model.EXT);

$model = ucfirst($model);
                
$CI->$name = new $model();    //<--- line 177



Fatal error: Class 'Test_model' not found... - El Forum - 03-25-2008

[eluser]Gary the Llama[/eluser]
Well, I'm just retarded. I hadn't put my start (&lt;?php) and end (?&gtWink tags in my model file. I'm sure it's a classic newbie mistake. Sad


Fatal error: Class 'Test_model' not found... - El Forum - 03-25-2008

[eluser]nirbhab[/eluser]
:-) some times it happens with senior members also...not a great issue...