3

I am trying to pull a listing of custom channel fields in my module and am refactoring to use EE models.

I tried

$this->EE->load->model('field_model');

but that didn't set $this->EE->field_model... as expected.

Any idea on how to use EE models in my module?

1
  • 1
    Please note the use of $this->EE implies that the latter code is in your module's controller (or other module file which requires the use of $this->EE =& get_instance();). Feb 26 '13 at 15:44
2

Another approach might be to turn your module into a package. You could put this in in your module's constructor (or a superclass to subclass it from for use in more than one class):

$this->EE->load->add_package_path(PATH_THIRD.'mymodulename');

Now mymodulename/models will be added as a path for your model files. and mymodulename/helpers for your helper files. You can then load the model.

$this->EE->load->model("mymodelname");
1

Looks like it works inside of my module's models BUT in a "Controller (mcp)" $this->EE->field_model doesn't seem to be accessible.

Simply use the following in the model instead:

$this->load->model('field_model');
$this->field_model...
3
  • 1
    Can you please edit your original question to include this information. We keep the answers section for actual answers. Thanks :) Feb 26 '13 at 6:08
  • Hi Adrian, I volleyed between adding it as a comment and an answer myself and found it was more suitable in the answers section. The solution is to add the call to load the model in your module's models. Feb 26 '13 at 15:41
  • You should definitely be able to load models in your controller though, so I'd be interested to find out why that's not working. Is is possible to post a link to the source of your full mcp file? Feb 27 '13 at 6:18
0

For anyone else expiriencing same issue, make sure the model's file name is lowercase.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.