0

In OOP (PHP, in my case),

class Hello{
    __construct($a, $b){
    return $a * $b;
    }
}

we pass the value to constructor as:

$hello = new Hello(5, 10);

Now, in codeigniter i have this library as Hello.

class Hello{
    __construct($a, $b){
    return $a * $b;
    }
}

and have loaded this library to my controller as

$this->load->library('hello');

How am i to pass argument on hello class for its constructor? any help will be greatly appreciated.

1 Answer 1

3

https://www.codeigniter.com/user_guide/general/creating_libraries.html

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

$this->load->library('Someclass', $params);
Sign up to request clarification or add additional context in comments.

2 Comments

i reckon what we need is large and red so why user type and color index?? cant' we just pass array('large', 'red')? if not why do we have to use index where we only want values?
You can also create an initialize() function if you want to pass multiple parameters. After loading the library, you would call it, and it would act like the constructor. A lot of CI's libraries do this.

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.