Welcome Guest, Not a member yet? Register   Sign In
Passing Boolean Arguments on Library Load
#1

[eluser]Unknown[/eluser]
Hi CodeIgniter Users,

im new to CI and i have a problem...

I have a single Boolean Argument in a Library Constructor and i would like to set it to true by default, like
Code:
__construct($param = true) { ... }
Smile
and in my Controller, i call it with
Code:
$this->load->library('LibName', false);
that doesnt work...as it sets the $param in the lib constructor to true, even if i call it with false.

To pass this, do i really have to use an array with a single element, like
Code:
$this->load->library('LibName', array('bool'=>'false'));
and treat the parameter as an array in the constructor of my Lib?

This just happens on a Windows Webserver with xampp php5 and CI1.7

The other machines are Linux, Mac with CI1.63 and the error doesnt happen at all.

I dont know if it is an issue with CI1.7 or something with the windows server ?
Im asking you because it looks a little strange to me to pass arrays with a single element to replace a boolean value, like the one i described above

Thanks in advance and sorry if my question is too noobie-like Wink

Adrian
#2

[eluser]Phil Sturgeon[/eluser]
Seems the second parameter must be an array. The offending section of code is:

system/libraries/Loader.php @ line 82
Code:
if ( ! is_null($params) AND ! is_array($params))
        {
            $params = NULL;
        }

The following will work:

Code:
$this->load->library('LibName', array('bool'=>false));
#3

[eluser]Unknown[/eluser]
Thanks alot Phil,

i wanted to ensure this before writing it to our Knowledge Base.

Cheers
Adrian




Theme © iAndrew 2016 - Forum software by © MyBB