Passing parameter when loading Library in Codeigniter

64 views Asked by At

I am trying to integrate the textlocal sms api if i pass three at the time of load library it's not working.

Error: Too few arguments to function Textlocal::__construct(), 1 passed and at least 2 expected

I have one Setupfile.php Library as following.

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Setupfile {

  function send($number, $message)
  {

    $ci = & get_instance();
    $data=array("username"=>'xyz',"hash"=>'abc','apiKey'=>false);
    $sender  = "xyz";
    $numbers = array($number);
    $ci->load->library('textlocal', $data); //passing paramenters

  }
}

and another Textlocal.php library as follows:

class Textlocal
{

    function __construct($username, $hash, $apiKey = false) //get into this function
    {

        $this->username = $username;
        $this->hash = $hash;
        if ($apiKey) {
            $this->apiKey = $apiKey;
        }

    }
}
1

There are 1 answers

0
Bhanu Pratap On BEST ANSWER

Basically I passed and array in the function and try to get the as a variable. Now I have solved this as getting an array()