We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Model cannot load from extension constructor

Development and Programming

Fritzinger's avatar
Fritzinger
35 posts
14 years ago
Fritzinger's avatar Fritzinger

I’m writing my own ExpressionEngine 2 extension that delegates some work to a model class. The constructor includes the line:

$this->EE->load->model('my_model')

The EE control panel fails on this line when I view the addons->extensions page. The message is “Unable to locate the model you have specified: my_model”.

I’ve used a debugger to step through the CI_Loader->Model() method, and I can’t see models from my other third party add-ons, e.g. DevDevmon’s Tagger… the complete list of models it does load is:

member_model
channel_model
template_model
site_model
addons_model
super_model
addons_model
my_model

… so presumably these are the only extensions which load models as part of the processing EE does when loading the addons->extensions CP page.

I can see why it fails - the list of model paths the method considers on line 172:

foreach ($this->_ci_model_paths as $mod_path)
{
  if ( ! file_exists($mod_path.'models/'.$path.$model.EXT))
  {
    continue;
  }
//...

…does not include system/expressionengine/third_party/my_module/models, it only checks system/expressionengine/models. So clearly I’m doing something unusual by loading a model in the extension constructor where it will be called when the extensions control panel page loads.

That said, I can’t see any warnings in the documentation or any reason why I shouldn’t be able to do that. In my case I’ve got the same code that needs to be called by both an extension and a module and it makes sense to put this stuff in a model.

I’m pretty sure the standard “make model name lowercase” advice is irrelevant here (not least because I made sure every possible reference was lower cased)… eager to here any other ideas you may have.

Fritz

[Mod Edit: Moved to the Development and Programming forum]

       
Txigreman's avatar
Txigreman
1 posts
14 years ago
Txigreman's avatar Txigreman

A possible workaround:

$this->EE->load->_ci_model_paths[] = dirname(__FILE__) . '/';
$this->EE->load->model('mymodel');
       
the3mus1can's avatar
the3mus1can
426 posts
14 years ago
the3mus1can's avatar the3mus1can

Check this out: https://support.ellislab.com/bugs/detail/15782/

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.