Welcome Guest, Not a member yet? Register   Sign In
$this->load->model('Account'); doesn't work.. i had to use $this->load->model('Account_model');
#1

[eluser]Rushino[/eluser]
Hello,

I have a model which is account_model.php (Account_model) it is normal that i had to call it using :


$this->load->model('Account_model');
$this->Account_model->insert_entry();

in the help file it seem we can use only the model name but it give me an error saying it couldnt find it.

$this->load->model('Account');
$this->Account->insert_entry();

and i think i can't rename the model account.php otherwise it won't work.

Thanks.
#2

[eluser]danmontgomery[/eluser]
Code:
$this->account_model->insert_entry();
// not
$this->Account_model->insert_entry();
#3

[eluser]Rushino[/eluser]
Hi there,

I tried your code but that doesn't change anything and btw ..

----
$this->load->model('Account_model');
$this->Account_model->insert_entry();
----

are working without problem with or without uppercase. Furthermore, that not the issue i was exposing.. you should read my post a bit more Tongue

If you look at the help file.. it tell us that we can load our models by using..

----
$this->load->model('Account');
$this->account->insert_entry();
----
while having as model filename account_model.php

but that doesn't work. I get this error.

----
An Error Was Encountered

Unable to locate the model you have specified: account
----

I was just wondering if it was a bug or not.

Thanks.
#4

[eluser]Twisted1919[/eluser]
File name must start with a uppercase character and continue with lowercase chars till the end.
Example: Account_model.php
Class definition in the file should be the same.
Example: class Account_model extends CI_Model{}
Loading of model is done in lowercase.
Example: $this->load->model('account_model'); $this->account_model->whatever();

Got it ?

L.E: i bet you are developing under windows right now.
You will have big surprises when you will go live with your site on a linux machine if you don't respect the file name / class name / load class convention .
#5

[eluser]Eric Barnes[/eluser]
I think you are wanting this:
Code:
$this->load->model(‘account_model’, 'account');
$this->account->method();
#6

[eluser]Rushino[/eluser]
@twisted1919 : thanks for theses infos. However i think your wrong. Filename must be in lower case and class name must have the first letter capitalized. Loading the model is same as class name (capitalized first letter and rest lower case) however that what the user guide tell us. Anyone can confirm?


@Eric barn : yes that what i was looking for so thanks but this isnt said in the user guide so correct me if i am wrong ? The exemple saying load('Account') is also wrong since the model name must have _model.php in filename and it seem that calling the model without this won't work.

Would like to have some clarifications / explanations on what ive said above.

Thanks!
#7

[eluser]Eric Barnes[/eluser]
It does not have to have _model in the file name. You could just use models/Account.php if you wanted. But most use _model or _m so that they do not have any class name collisions with controllers or other files.
#8

[eluser]Rushino[/eluser]
Alright that good to know! Then i will simply use your suggestion as second parameter.
#9

[eluser]danmontgomery[/eluser]
http://ellislab.com/codeigniter/user-gui...odels.html

Quote:Where Model_name is the name of your class. 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. For example, if your class is this:

Not sure where you're seeing otherwise.
#10

[eluser]Rushino[/eluser]
Yeah but the object name had nothing to do with filename ?




Theme © iAndrew 2016 - Forum software by © MyBB