0

I am trying to dynamically set a codeigniter constructor, but am having difficulty. I have in my controller:

$arguments=array('login'=>'***','pass'=>'***');  ;                   
$this->load->library('mailer', $arguments);
$phpmail = new Mailer;
$phpmail->sendmail('***', 'bob', 'hi', 'there');

My constructors first line looks like:

public function __construct($login,$pass)

but I'm getting the following:

Message: Missing argument 1 for Mailer::__construct(), 

Any ideas what I am doing wrong?

Thanks in advance,

Bill

1 Answer 1

2

From the docs:

In the library loading function you can dynamically pass data as an array via the second parameter and it will be passed to your class constructor:

$params = array('type' => 'large', 'color' => 'red');

$this->load->library('Someclass', $params);

If you use this feature you must set up your class constructor to expect data:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Someclass {

    public function __construct($params)
    {
        // Do something with $params
    }
}

?>

The first argument is the exact array you passed. Use $params['login'] and $params['pass'] instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.