Welcome Guest, Not a member yet? Register   Sign In
User's library can't use the __construct method passing parameters???
#1

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........
Reply
#2

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!
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
Reply
#3

(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.......
Reply




Theme © iAndrew 2016 - Forum software by © MyBB