Passing arguments when loading custom CodeIgniter library Passing arguments when loading custom CodeIgniter library codeigniter codeigniter

Passing arguments when loading custom CodeIgniter library


You need to modify your class constructor to handle the passed data as described here:

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

public function __construct($params){    $array1 = $params[0];    $array2 = $params[1];    $string = $params[2];    // Rest of the code}


you forgot the $ on array2 when declaring params, causing it be passed as a constant that isn't defined instead of an array.


Passing Parameters When Initializing Your Class

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    }}?>