Welcome Guest, Not a member yet? Register   Sign In
Loading a model function
#1

[eluser]tfliam[/eluser]
Hi, just have this small issue with the coding of loading a model.
The code below works fine:

Code:
$this->load->model('ValueWebData', 'fubar', TRUE);
        $this->fubar->getTitleByController();

However when I try to access the the same thing using an object with the same name of the class, it shows an error, the code is as such:

Code:
$this->load->model('ValueWebData', TRUE);
        $this->ValueWebData->getTitleByController();

And the error shown is :
Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Home::$ValueWebData
Filename: controllers/home.php
Line Number: 13

Anyone have any idea how to access the model using object with the same name of the class?
#2

[eluser]xwero[/eluser]
Loading the model create an object variable that is lowercased or only capitalized the first letter so Valuewebdata and valuewebdata will work. It is a thing CI enforces because the preferred naming of classes is using underscores between the words. It's not a good thing in my opinion and it is mentioned in the request feature section.
#3

[eluser]tfliam[/eluser]
Thanks for the reply, however after I named it to small cap, it still doesn't work.

This Doesn't Work
Code:
$this->load->model('valuewebdata',TRUE);
        $this->valuewebdata->getTitleByController();


This Works
Code:
$this->load->model('valuewebdata', 'valuewebdata',TRUE);
        $this->valuewebdata->getTitleByController();
#4

[eluser]xwero[/eluser]
I overseen the fact that you added TRUE as second parameter instead of third parameter. That should be the solution.
#5

[eluser]tfliam[/eluser]
yes...should be
$this->load->model('valuewebdata', '',TRUE);
$this->valuewebdata->getTitleByController();

Thank you very much.




Theme © iAndrew 2016 - Forum software by © MyBB