Welcome Guest, Not a member yet? Register   Sign In
Passing parameter to a custom library constructor
#1

[eluser]upstream[/eluser]
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 ^^.

Thanks,
Rico
#2

[eluser]pistolPete[/eluser]
Did you try this?
Code:
$config = array('setting_1' => 'value_1', 'setting_2' => 'value_2');
$this->load->library('email', $config);

The $config array should be passed to the constructor.
#3

[eluser]upstream[/eluser]
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?
#4

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

Code:
$this->load->library('email');

$params['smtp_port'] = 25;
$this->email->initialize($params);




Theme © iAndrew 2016 - Forum software by © MyBB