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

[eluser]rob897[/eluser]
I have a couple models for this application and just noticed I needed to call one of the functions from another model...

dbs_model
Code:
class DBS_Model extends Model {

    function DBS_Model()
    {
        parent::Model();
        $this->load->model('account_model');
    }

account_model
Code:
class Account_Model extends Model {

    function Account_Model()
    {
        parent::Model();
        $this->load->model('dbs_model');
    }

Do these conflict each other as each one calls the other?
I have tried to autoload all my models in the config, but the one function within the dbs_model fails with the following error:
Code:
Severity: Notice

Message: Undefined property: Account_Model::$dbs_model

Filename: models/account_model.php

Line Number: 268

Fatal error: Call to a member function Backup() on a non-object

I know this may look confusing but I hit a dead end here and I not sure why I simple just couldn't load the dbs_model and call its function within the account_model..
If I leave the load dbs_model in the constructor, one of the functions with the account model actually prompts me to download a binary file... and as soon as I comment out the load dbs_model it works fine...

Help!!
#2

[eluser]rob897[/eluser]
From what I read, you shouldn't load models within models, they should be loaded from the controller... so I will see if I can fix my coding to leave out any models that load more models.... but I really need some help here.

-rob
#3

[eluser]sl3dg3hamm3r[/eluser]
I also would suggest you need to redesign it somehow. Two classes (or in that case models) who associate each other, that's a weird constellation...
#4

[eluser]rob897[/eluser]
So lets say I have this:

Code:
class Account extends Controller {

    function Account()
    {
        parent::Controller();
        $this->load->model('account_model');
        $this->load->model('hosting_model');
        $this->load->model('dbs_model');
    }
}
Can I assume that all the functions within the other models loaded are available throughout this entire controller?

So I should be able to call any of the dbs_model function from within this controller.

I think my problem is that I am trying to call dbs_model->Backup() within the account_model itself. I think I get it but just want to make sure.

-rob
#5

[eluser]sl3dg3hamm3r[/eluser]
[quote author="rob897" date="1225138286"]Can I assume that all the functions within the other models loaded are available throughout this entire controller?[/quote]

Jep, that's right.
#6

[eluser]rob897[/eluser]
So then with this controller
Code:
<?php
class DBS extends Controller {

    function DBS()
    {
        parent::Controller();
        $this->load->model('dbs_model');
        $this->load->model('account_model');
        $this->load->model('hosting_model');
    }

    function Edit()
    {
        $this->dbs_model->Edit();
    }

    function Delete()
    {
        $this->dbs_model->Delete();
    }

    function Create()
    {
        $this->dbs_model->Create();
    }

    function Backup()
    {
        $this->dbs_model->Backup($database='',$domain='',$uid='');
    }

    function Update()
    {
        $this->dbs_model->Update();
    }
}

Within the "accounts_model" class there are functions that return account information, I think I am accessing these directly from the model and not the controller so for instance, I have in the dbs_model something that returns:
Code:
$this->account_model->SearchAccounts($domain);
Should I be getting this info from the controller instead....? I think this is where my problems are.




Theme © iAndrew 2016 - Forum software by © MyBB