Welcome Guest, Not a member yet? Register   Sign In
Passing a second variable into a custom library
#1

[eluser]WoolyG[/eluser]
Hi,
I have a custom library as follows:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Someclass_library {

    public function __construct($key, $options = array())
    {
      //Do awesome stuff
    }
}

/* End of file Someclass.php */


I'm using the following, which works:

Code:
<?php
$someclass_data = array("key" => "mykeygoeshere");
$this->load->library('Someclass_library', $someclass_data);



What I'm trying to do is to utilise the second parameter of the __construct. How do I do this? I'm trying the following, but it's not working:

Code:
<?php
$someclass_data = array("key" => "mykeygoeshere");
$option = array("application" => "myapplication");
$this->load->library('Someclass_library', $someclass_data, $option);


.. can anyone shed any light on how to access the second parameter of a __construct() when loading a custom library?

Thanks!
WoolyG
#2

[eluser]vbsaltydog[/eluser]
http://ellislab.com/codeigniter/user-gui...oader.html

The first parameter is the library, the second is the array of options, the third is an optional object name.

Take your key and other options, put them all in a single array, pass that array as the second parameter, then array_shift the key off of the array in the library constructor.

#3

[eluser]WoolyG[/eluser]
Thanks for that. For what it's worth, a clear method of doing what I need to do is outlined in the first reply to this StackOverflow question:

http://stackoverflow.com/questions/34806...er-library



I was thinking the User Guide (http://ellislab.com/codeigniter/user-gui...aries.html) might be a little unclear on how to pass multiple parameters to the custom library's __construct..


I'll put forward a suggestion to possibly have it clarified. Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB