0

this is my problem. I'm using codeigniter and this is my structure. I have 2 classes in 2 files

class Model_setup extends CI_Model 
{
    //functions

    // an update function
    public function update()
    {
        // update stuff
    }
}

// OTHER FILE

class Tests extends Model_setup
{
    // other functions....

    // a totally different update function
    public function update()
    {
        // update a specific set of stuff
    }
}

I want to know if and how it is possible to reference these two separate update functions. In a separate controller from these two, say the Places_Controller how would you tell the difference between these two class methods and how would you make sure that you are only using one or the other of the two updates? Thank you for the help in advance.

7
  • 3
    Thanks god it's not possible in php Commented Nov 12, 2012 at 23:53
  • @zerkms - I feel stupid, but if you create a Model_setup object, won't you have access to the parent update? Commented Nov 12, 2012 at 23:56
  • @Joseph Silber: to the parent or child? Commented Nov 12, 2012 at 23:57
  • @zerkms - Creating two separate objects. See my answer. This is elementary. I suspect you read too much into the question. And yes, thank god (!) what you mean is not possible in PHP. Commented Nov 12, 2012 at 23:58
  • @Joseph Silber: well, the question is asked poorly, so I wouldn't be so sure you understood it correct. PS: "creating 2 separate objects" looks so strange in CI :-S Commented Nov 12, 2012 at 23:59

2 Answers 2

1

Assuming you're loading both models, you just reference them by name:

$this->Model_setup->update();

will refer to that first method, while

$this->Tests->update();

will refer to the second one.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm looking into this now, there seems to be more at work here with my class structure than I thought. I will update soon. Thanks for the help.
Do you have to manually load or auto load child models/classes?
1

So I was enlightened by a friend about how to solve this. This doesn't need any codeigniter frmaework stuff to be made to work correctly. The following would work correctly:

class Model_setup extends CI_Model 
{
    //functions

    // an update function
    public function update()
    {
        // update stuff
    }
}

// OTHER FILE

class Tests extends Model_setup
{
    // other functions....

    // a reference function to the parent function
    public function parent_update($x)
    {
        // update a specific set of stuff
        parent::update($x);
    }

    // a totally different update function
    public function update()
    {
        // update stuff
    }
}

Now from the outside world, say another controller in the framework you can call the following once everything has been loaded. $this->tests_model->parent_update($x) when you wish to call the parent version and $this->tests_model->update when you wish to call the update function for the Tests model. This worked and I have tested this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.