Is it OK to use EE model methods in addons or is that considered bad form?
My Health Check accessory caused a bit of trouble for people because I’m using this method to pull a list of available plugins:
$this->EE->addons_model->get_plugins();That method does an include_once() on each plugin file.
#Line 136 of models/addons_model.php:
@include_once(PATH_PI.$file)However, the page that displays plugins on the control panel uses another method that also tries to include_once() each plugin file.
#Line 612 of controllers/cp/addons_plugins.php
@include_once($path);Since the include_once() in my accessory gets called first on every CP page load, the include_once() on the CP’s plugin list page doesn’t include the plugin files (because they’ve already been included) and fails silently.
If I change that second include in addons_plugins.php on line 612 to:
include($path);I get this fatal error:
Fatal error: Cannot redeclare map_attrs() (previously declared in /www/ypadmin/expressionengine/plugins/pi.magpie.php:1188) in /www/ypadmin/expressionengine/plugins/pi.magpie.php on line 1190
So, it seems the assumption is that the list plugin call will only be made once and not by an addon.
I can certainly walk the plugins directory manually to find plugins, but assumed the existing model method would be the “better” solution.
Am I thinking about this correctly? Or is it better to not touch model methods? Or is it a shortcoming of the plugin implementation?
Appreciate any feedback or ideas.
Personally, I use the built in EE models and libraries as much as I can in my add-ons. I’m lazy, so why reinvent the wheel, you know?
The key seems to be picking your battles and know the code you’re using. For instance, I ran into your exact specific issue previously (though for a different reason) and it was, for me, a situation where rolling my own was the proper call for my need. Again, like you, I found iterating over the directory made way more sense than fighting with the “almost can” of the EE method.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.