Welcome Guest, Not a member yet? Register   Sign In
Help! - Problem loading models
#1

[eluser]naftolir[/eluser]
Hi all,

I am a newbie to CI. I just started using it for a project.

I seem to be having a problem loading more than three models within the same function.

Example code:

public function add() {
$data['fields'] = $this->orders_model->getMappedFields();
$this->load->model('clients_model');
$data['clients'] = $this->clients_model->getAllByName();
$this->load->model('status_model');
$data['status'] = $this->status_model->getAll();
$this->load->model('items_model');
$data['itemFields'] = $this->items_model->getMappedFields();
$data['items'] = $this->items_model->getAllToView();
$this->load->model('order_items_model');
$data['orderItemFields'] = $this->order_items->getMappedFields();
$this->load->view('orders/add', $data);
}

This is in one of my controllers.

When I go to the view page I get this error:

"A PHP Error was encountered

Severity: Notice

Message: Undefined property: Orders::$order_items

Filename: controllers/orders.php

Line Number: 24"

I only get this error after loading three models, if I take away one loaded model in the function, it works fine.

Any help will be greatly appreciated.

This project is being hosted on godaddy.

thanks,

naftoli rapoport
#2

[eluser]CroNiX[/eluser]
Code:
$data['orderItemFields'] = $this->order_items->getMappedFields();
Should that be order_items_model, which would also be the reason why order_items is undefined? I'm assuming here since you are loading the model order_items_model on the line above it and also the error message.
#3

[eluser]marcogmonteiro[/eluser]
I'm not sure about this, but I think this as to do with your model name. Models should be modelname_model and not something_something_model.

Do you have problems with just this model or does the problem persists if you change the order that you're loading your models and it's always the 3rd+ one?
#4

[eluser]naftolir[/eluser]
It doesn't have to do with "something_something_model" as oppose to "something_model" b/c when i try a different to load a different model that is in the format of "something_model" it still doesn't work.

It seems to always be the fourth model+.
#5

[eluser]CroNiX[/eluser]
read what I wrote.
$this->order_items
doesn't exist, or at least the code you provided doesn't show you loading it.
Try
$this->order_items_model...
#6

[eluser]marcogmonteiro[/eluser]
yep @CroNiX is completely right =)

#7

[eluser]naftolir[/eluser]
hey good point Smile
#8

[eluser]naftolir[/eluser]
so then why doesn't the following work?

Code:
$this->load->model('clients_model');
  $data['fields'] = $this->clients_model->getMappedFields();
  $data['codes'] = $this->clients_model->getCodes();

        $this->load->model('contacts_model');
        $data['contacts'] = $this->contacts_model->getContactNames();
  
  $this->load->model('addresses_model');
        $data['addressFields'] = $this->addresses_model->getMappedFields();
        $data['types'] = $this->addresses_model->getTypes();
        
        $this->load->model('phones_model');
        $data['phoneFields'] = $this->phones_model->getMappedFields();
        
        $this->load->model('emails_model');
        $data['emailFields'] = $this->emails_model->getMappedFields();
  
  $this->load->view('clients/add', $data);

When it gets to the $this->phones_model it says "Message: Undefined property: Clients::$phones_model"




Theme © iAndrew 2016 - Forum software by © MyBB