• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing parameter to a custom library constructor

Hi all,

Using code igniter. is it possibile to pass a value in a constructor's parameter? like this:

My_Email library
Quote:class My_Email extends CI_Email
private $CI;
private $email_account;

public function __construct($config_item = '')
$this->CI =& get_instance();

$this->email_account = $this->CI->config->item(($config_item=='' ? 'email_account' : $config_item));

I want to pass an optional config in the constructor so i can use other config item besides the default email_account.

Problem is. i dunno how to pass a value on my constructor in my model since ci load class via $this->load.

i do not want to add any addditional function since im just expanding this class a bit and other modules are already using this.

Please help ^^.


Did you try this?
$config = array('setting_1' => 'value_1', 'setting_2' => 'value_2');
$this->load->library('email', $config);

The $config array should be passed to the constructor.

i tried but it doesnt output any when i echo the parameter of the constructor. also i just want to pass the item name of the config. any other ideas?

Like most CI system libraries, Email library has "initialize" method. Passing array to this method will override object properties, for example:


$params['smtp_port'] = 25;

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.