Welcome Guest, Not a member yet? Register   Sign In
The case-sensitivity has me confused -- Probably not a case-sensitive problem, but problem still not resolved
#1

[eluser]geitvdplas[/eluser]
Hi,

I tried searching for a solution, but nobody seems to have had the same problem.

I developed my CI application with easyphp on windows-xp, and I'm trying to make it work online now on a linux server too. Of course that always brings a few bugs that need to be solved, but this one is a real pain. My models won't load!

The userguide tells me this:

Code:
$this->load->model('Model_name');

$this->Model_name->function();

Now note the capital M! But, when I try to load my model like this:
Code:
$this->load->model('Datafile_model');
$this->Datafile_model->store_datafile($data);

It does not work. Neither does it work when I lowercase the names.

So far the only solution to this is autoloading my datafile_model. And my guess is that it's because in the autoload config file you do NOT capitalize the first letter of the model.

Ugh, I'm confused, maybe I'm looking in the wrong direction? Bottom line is: when I autoload my models the first letter doesn't have to be capitalized and the model loads just fine, but when I do it the 'normal' way it doesn't work.

Here's the error I get:
Code:
Severity: Notice
Message: Undefined property: Upload_datafile::$Datafile_model
Filename: actions/upload_datafile.php
Line Number: 63

I have also attached an image showing how the user guide explains the model loading.
#2

[eluser]WanWizard[/eluser]
It's not about how you name the class (although it's best to use the documented standard), but how you name the file.

A Windows filesystem is case-insensitive, so TEST and TeSt in Windows is the same file. In Unix(Linux/Mac), the filesystem is case sensitive, so these are different files.

The manual states that you should save your files with lowercase names. So the model 'Model_name' should be defined in the file 'model_name.php'. Otherwise it's not able to load it.

PHP is also case sensitive for variable names, so $this->Data_model is a different variable than $this->data_model. Afaik they are created lower case, so you should use the latter (which means there's a mistake in the user guide).
#3

[eluser]geitvdplas[/eluser]
Thanks for your reply!

Are you suggesting I should type them both lowercase? As, naturally, I've already been trying every possible way.
Code:
$this->load->model('datafile_model');
$this->datafile_model->store_datafile($data);
Does not work either. It only works when I autoload the models! Is it perhaps a server setting I should change?

So far no solution besides autloading the models wich isn't really much of a problem but still. I can't stand it if it doesn't work like it is supposed to!

My model file is at:
Code:
application/models/datafile_model.php

Also in my first post I stated that it doesn't load the model, but it does, actually.. but it only does the constructor method. It's still an Undefined property for the controller I load it from.


If anyone could help me I will be the happiest man on the planet. Nothing is working for me. Message: Undefined property: Upload_datafile::$Datafile_model.
#4

[eluser]WanWizard[/eluser]
Did you extend the model class?
Code:
class Datafile_model extends Model

If you didn't, the property will not be assigned (it's something done by the constructor of the Model class).
#5

[eluser]vitoco[/eluser]
Maybe has nothing to do with the actual correct way to load models, but, i always name my models with a capital M at the start of the name, it also helps to avoid adding 'model' to the name, so every object that starts with a 'm'+word it's a model
Code:
class Datafile_model extends Model
i will put it like this
Code:
class MDatafile_model extends Model
and in the controller, don't have any problem calling the model lowercase
Code:
$this->load->model('mdatafile_model');
$this->mdatafile_model->method();

Saludos
#6

[eluser]geitvdplas[/eluser]
No, it doesn't seem to be that easy, I'm sorry...

Here's my problem in more detail:

datafile_model.php
Code:
<?php
class Datafile_model extends Model {
    
    function Datafile_model(){
        parent::Model();
        echo 'Model parent test: ';
        echo parent::_test(); // I added the method to the Model.php and it just echo's "I am loaded" to make sure it is extending properly
      }
    function test(){
        echo 'method is working';
    }
}
?>

The controller
Code:
echo "Datafile_model: ";
$this->load->model('datafile_model');
echo "<br/>Calling the method: ";
$this->datafile_model->test(); // this is where it fails
echo "  ___end";

Outputs:
[code]Datafile_model: Model parent test: I am loaded
Calling the method:
A PHP Error was encountered

Severity: Notice
Message: Undefined property: Upload_datafile::$Datafile_model
Filename: actions/upload_datafile.php
Line Number: 63

So everything works just fine until it tries to call a method. It's as if the load function doesn't create the property like it should. I have no idea what is going on under the hood of codeigniter with that load model.. Anyone got an idea?
#7

[eluser]WanWizard[/eluser]
This has nothing to do with the code you showed.

It complains that the property 'Tab_view_datafiles' is not defined within the datafile_model. This property is referenced on line 33 of the tabs/tab_datafiles.php file.
#8

[eluser]geitvdplas[/eluser]
Ah I'm sorry I pasted the wrong error, edited now.. same error as first post (only the line number could be different of course)
#9

[eluser]Unknown[/eluser]
I also have a similar problem of my model not being loaded and the solution is not simply naming the model class file to lowercase. I developed my code on Windows XP platform and the production server is a SUSE Linux 10 server with Apache 2.2/PHP 5.2.5.
I've tried every combination of renaming to lowercase filenames, class names, model variable names and determined the case-sensitivity is not the problem in my case. (pun not intended) I've also tried autoloading my model and it's still not working. If anyone has run across this problem, please let me know. I've been banging my head on the desk, but that doesn't work either.

In the above post, your using the PHP4 constructor, where if you're running PHP5+, you'll need to use the "__construct()" format, otherwise you're class will not load properly.

=========================================================================================
FYI, I resolved the issue I was having with loading models due to case-sensitivity. Initially, I had renamed the model's filename to lowercase, but they didn't fix anything. I renamed everything (class name, file name, variable name) to lowercase, but that didn't fix anything.
Then I renamed just the model file to lowercase and left other references to use upper case (camel casing), then reuploaded the entire website. Then magically it started working. I really don't think any files were out of sync, because I uploaded all the files via my IDE (Eclipse), but after I re-uploaded everything via FTP client, the models load fine.
Perhaps, the above poster can just simply try reuploading everything to see if that have any affect. I know it doesn't seem like it should, but I've seen stranger things happen before.

cheers,
Tony C.
#10

[eluser]WanWizard[/eluser]
The class will load fine in PHP5+ when you use a PHP4 type constructor. You are only required to use "__construct__" if you use namespaces.

As to naming, the manual states:
Quote:Class names must have the first letter capitalized with the rest of the name lowercase. Make sure your class extends the base Model class. The file name will be a lower case version of your class name.

@geitvdplas:

What platform are you using? Which PHP version? Can you check the output of
Code:
var_dump($this->datafile_model);

The error is not that test() can not be found, but that the property $this->datafile_model doesn't exist. Which is odd, "parent::Model();" should have taken care of this assigment.

Can you check if this is correct by changing the code to
Code:
$CI =& get_instance();
$CI->datafile_model->test();
and see if that works? If it does, you might have broken something in the model class (you've said you've modified it, which you shouldn't). If it doesn't, the model hasn't been loaded properly (which, given the output, I don't think its the case).




Theme © iAndrew 2016 - Forum software by © MyBB