CodeIgniter Forums

Full Version: User's library can't use the __construct method passing parameters???
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
today i create a library with a method __construct ,and the construct method have two parameters ,it's like this
Class Test
{
     private $a;
     public  function __construct($b)
     {
            $this->a = $b;
      }
      public function show()
      {
            echo $this->a;
       }
 }

but when i load the this library in  my controller, it posts an error saying that the __construct method missing one parameter

so the question is that is the library in Codeigniter can't use the __construct() method to passing parameters???????

help please........
Hi, leon hou, and welcome to CodeIgniter and the forums! Smile

What you are doing is ok, but when you load the library, you must pass the argument at that time. It's missing one parameter probably because you are not sending it. When you load the library, you must use something like
$this->load->library('test', $arguments);

Check out these pages.
https://www.codeigniter.com/user_guide/g...aries.html
http://stackoverflow.com/questions/12953...odeigniter
http://stackoverflow.com/questions/34806...er-library
http://stackoverflow.com/questions/10655...odeigniter

I hope that helps!
(03-10-2016, 10:33 PM)RobertSF Wrote: [ -> ]Hi, leon hou, and welcome to CodeIgniter and the forums! Smile

What you are doing is ok, but when you load the library, you must pass the argument at that time. It's missing one parameter probably because you are not sending it. When you load the library, you must use something like
$this->load->library('test', $arguments);

Check out these pages.
https://www.codeigniter.com/user_guide/g...aries.html
http://stackoverflow.com/questions/12953...odeigniter
http://stackoverflow.com/questions/34806...er-library
http://stackoverflow.com/questions/10655...odeigniter

I hope that helps!
thank you very much ,get that , i am using the wampserver integrating a debugger.......