Welcome Guest, Not a member yet? Register   Sign In
[Solved] Email Config File Question
#5

(07-25-2015, 02:50 AM)Dracula Wrote: You don't load the file with:


PHP Code:
$this->load->library('email'

...because it's not a library it's a config file.

As he was trying to point out, when you load a library, CI's loader automatically attempts to locate a config file with the same name (in all lowercase or ucfirst(strtolower($class))), including checking for environment-specific config files (if both exist, it will load the global first, followed by the environment-specific file). Then it instantiates the library and passes $config to the constructor. So, as long as the constructor handles the $config data passed from the config file(s), the library will automatically be configured according to the config file(s).

This also works with your own libraries if you define your constructor as receiving an array parameter and add a config file named after your library. For example, I recently modified Bonfire's installer library to use a config file, so the constructor looks something like this:


PHP Code:
   public function __construct($config = array())
 
   {
 
       if (! empty($config['writable_folders'])) {
 
           $this->writable_folders $config['writable_folders'];
 
       }
 
       if (! empty($config['writable_files'])) {
 
           $this->writable_files $config['writable_files'];
 
       }

 
       $this->ci =& get_instance();
 
       $this->curl_update $this->cURL_enabled();
 
       $this->php_version phpversion();
 
   

When we load the installer library, we don't have to load the config file ourselves and pass it to the library, we just tell CI to load the library. I assume that the values could be empty, because someone using Bonfire could either not add the config file or remove the entries from the file, but in a default installation the variables will be set without having to do anything else.
Reply


Messages In This Thread
RE: Email Config File Question - by Diederik - 07-24-2015, 09:01 PM
RE: Email Config File Question - by Dracula - 07-25-2015, 02:50 AM
RE: Email Config File Question - by Wouter60 - 07-25-2015, 03:42 AM
RE: [Solved] Email Config File Question - by mwhitney - 07-27-2015, 09:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB