Howdy
I wanted to check in here before I make this a feature request or bug report. I may be doing something wrong or missing a better existing route here.
I’ve used configs in CI apps before and I’d very much like to keep consistency using configs (when needed) in EE2 add-ons. A simple example would be holding info about an add-on package like Name, Version & Docs link within a config file to be used across all add-on package files.
My initial thought was to just create a third_party/package/config/config.php file assuming it was auto-loaded with each file (like an accessory, mod, etc). However I noticed that wasn’t the case. Since things like add-on version and docs links are typically class variables I wasn’t sure what the best way was to load this config file. I also tried making it package_name.php rather than config.php.
If I just load the config in my constructor I get an error message. Consider the following code:
// this is in the file acc.my_package.php
// relative to this file I am trying to load config/my_package.php
function My_package_acc()
{
$this->EE =& get_instance();
$this->EE->config->load('my_package');
}That produces the following error:
The configuration file my_package.php does not exist.
What’s weird is that the config file appears to actually load. Consider the following code:
// this is in the file acc.my_package.php
// relative to this file I am trying to load config/my_package.php
function My_package_acc()
{
$this->EE =& get_instance();
$this->EE->config->load('my_package');
exit(var_dump($this->EE->config->item('my_package_version')));
}That accurately spits out the string version stored in the $config array of config/my_package.php.
So, the error message says the config file isn’t loading (or more specifically “does not exist” but the var_dump method clearly shows a loaded config array.
Note that removing the config load line (to test the auto-load theory) makes the value “false” (meaning I still need to load the file).
So, the seems like a bug of sorts. Can you confirm?
While we’re on the topic…
Would you consider auto-loading a primary config file with add-ons so we can use $this->EE->config-item() in the class variables? That would make the add-on more CI-like in my opinion. Technically I could go ahead and use an include() at the top of my files and do this myself. Just a thought 😊
This just in:
If I drop my config file into the expressionengine/config directory it does not return the error message. I imagine it’s a matter of paths in the config loader at this point.
For what it’s worth, the “config” info area in the add-on docs is pretty minimal (though if this is indeed a bug then it’s understandable).
Thanks Bjørn.Rob (_rsan) noted you could reverse that and make the path relative to the system config directory.
http://twitter.com/_rsan/status/15835754890530816
It seems that the error message only appears on the Add-Ons => Accessories page which leads me to believe it is a bug in EE.
Ok, yup, I use that when loading a config that is shared by several addons:
$this->EE->load->config('../third_party/config/global');.. but that shouldn’t be neccessary if you’re loading a config file that resides in your <youraddon>/config/ directory. Might be a bug with accessories only though (?)..
For what it’s worth, I’ve turned this discussion into a bug report and a feature request.
Hey Eric for what it’s worth, I have a few helper functions that I use.
Contents of config file:
<?php
$params = array();
$params['version'] = "";
$params['param2'] = "";
$params['param3'] = "";
$params['param4'] = FALSE;
/* End of File: config.php */Function in addon:
function _load_config()
{
$filename = dirname(__FILE__) . '/config.php';
if( empty($this->config) AND file_exists($filename) )
{
include $filename;
$this->config = $params;
}
$this->config['version'] = (empty($this->config['version']) ? '' : $this->config['version']);
$this->config['param2'] = (empty($this->config['param2']) ? '' : $this->config['param2']);
$this->config['param3'] = (empty($this->config['param3']) ? '' : $this->config['param3']);
$this->config['param4'] = (empty($this->config['param4']) ? '' : $this->config['param4']);
}I also have a save_config helper but the main purpose of that is to manipulate the data that is being saved..
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.