Welcome Guest, Not a member yet? Register   Sign In
Can't load models...error in line 184 of Loader.php
#1

[eluser]MydKnight[/eluser]
Hi all,

I am brand new to the CodeIgniter framework and working through some test cases. I am not sure what I am doing wrong, but I can't get my model to work. I have it in system/application/models. its called m_test.php with the following code;

class m_test extends Model{
function m_test(){
parent::Model();
}
}

I am calling it in my controller via:

$this->load->model("m_test");

and when I try that I get the following:

class m_test extends Model{ function m_test(){ parent::Model(); } }
Fatal error: Class 'M_test' not found in /home/abadmin1/public_html/rework/system/libraries/Loader.php on line 184

Can anyone tell me what would cause this?
#2

[eluser]Colin Williams[/eluser]
Classes and functions shouldn't be case sensitive, but you should follow the naming conventions anyway. Make it 'class M_test' and see if that works.
#3

[eluser]FutureKing[/eluser]
[quote author="MydKnight" date="1246183881"]Hi all,

I am brand new to the CodeIgniter framework and working through some test cases. I am not sure what I am doing wrong, but I can't get my model to work. I have it in system/application/models. its called m_test.php with the following code;

class m_test extends Model{
function m_test(){
parent::Model();
}
}

I am calling it in my controller via:

$this->load->model("m_test");

and when I try that I get the following:

class m_test extends Model{ function m_test(){ parent::Model(); } }
Fatal error: Class 'M_test' not found in /home/abadmin1/public_html/rework/system/libraries/Loader.php on line 184

Can anyone tell me what would cause this?[/quote]

You forgot to capitalize the letter M in first line.
It should be like this...
class M_test extends Model
#4

[eluser]MydKnight[/eluser]
I'd forgotten about the tweaking I did and forgot to undo it before posting. The error has changed slightly. To update, the model is called M_test, its called via my welcome controller as $this->load->model("M_test"); and the model itself is as follows:

class M_test extends Model{
function M_test(){
parent::Model();
}
}

When I load the page in question I get:

An Error Was Encountered
Unable to locate the model you have specified: m_test

Any ideas?
#5

[eluser]ok3x[/eluser]
When loading a model, you should call
Code:
$this->load->model('m_test');
The parameter string of the model's name is lowercase, although the class declaration of the model goes like this M_test.
Also make sure, you placed the file "m_test.php" (lowercase) to the model directory within your app's directory.
#6

[eluser]MydKnight[/eluser]
Back to the can't load model error now. To recap:

The file is in application/models and is called m_test

The call to the model is $this->load->model("m_test");

The model text is:

class M_test extends Model{
function M_test(){
parent::Model();
}
}
#7

[eluser]pj_mfc[/eluser]
Make sure you have opening and closing php tags in your model file:

Code:
<?php

class M_test extends Model{
  function M_test(){
      parent::Model();
  }
}

?>
#8

[eluser]MydKnight[/eluser]
OK, I am pretty much officially a n00b...and a moron.

The php tags where what killed me. Seems to work now. Thanks to all for your prompt help!
#9

[eluser]pj_mfc[/eluser]
I made the same mistake and have been using PHP for years. Looking through the forum, a couple other users have had the same problem. I know the docs contain code snippets, but it definitely wouldn't hurt to throw the php tags into the examples because many people cut and paste to start out and the error message tells a beginner almost nothing useful.
#10

[eluser]johnnyForums[/eluser]
[quote author="pj_mfc" date="1246401926"]I made the same mistake and have been using PHP for years. Looking through the forum, a couple other users have had the same problem. I know the docs contain code snippets, but it definitely wouldn't hurt to throw the php tags into the examples because many people cut and paste to start out and the error message tells a beginner almost nothing useful.[/quote]

Thanks. I had the same problem and am new to php.




Theme © iAndrew 2016 - Forum software by © MyBB