0

This is a [seemingly] simple question and I'm hoping I get a quick answer as my afternoon depends on the answer :D

In Codeigniter, if I create a named instance of a model in another model, what is the scope of the new object?

hope this clarifies a bit more:

If in 'user_model' I create an instance of 'logging_model' thus:

$this->load->model('logging_model', 'logging');

if in 'post_model' I need access to the new 'logging' instance created in the user model, do I just call the same piece of code in the constructor/function that I need to have access?

so if user_model sets an attribute of $this->logging->posts = 0;

I want post_model to access the 'posts' attribute with the newly set value, would just by instantiating the logging_model with the same instance name (logging) inside posts_model give access to the object created by user_model?

2 Answers 2

1

do I just call the same piece of code in the constructor/function that I need to have access?

No - if you need the model in multiple places you should call it in config/autoload.php

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

Comments

1

To load a model you will require to write

$this->model->(your model name here)

To load globally you will require to call your model in application/config/autoload.php

$autoload['model'] = array('your model1', 'your model2');

I hope this is helpful.

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.