Welcome Guest, Not a member yet? Register   Sign In
Library loader - possible bug - feedback requested.
#1

[eluser]TheFuzzy0ne[/eluser]
I noticed what looks like a mistake in the CI_Loader class, and wanted to confirm it.

Code:
function library($library = '', $params = NULL, $object_name = NULL)
    {
        if ($library == '')
        {
            return FALSE;
        }

        if ( ! is_null($params) AND ! is_array($params))
        {
            $params = NULL;
        }

        if (is_array($library))
        {
            foreach ($library as $class)
            {
# Should this really be calling all classes in the array with the same parameters?
                $this->_ci_load_class($class, $params, $object_name);
            }
        }
        else
        {
            $this->_ci_load_class($library, $params, $object_name);
        }
        
        $this->_ci_assign_to_models();
    }

I would have thought it would be better off just using NULL and FALSE for the second and third parameters.
#2

[eluser]Colin Williams[/eluser]
Quote:Should this really be calling all classes in the array with the same parameters?

Probably not. Maybe $params could go through, but $object_name would definitely raise issues. They probably just didn't test against a developer trying to load multiple libs with the same params and object name (not sure why anyone would even try... wouldn't make any sense).
#3

[eluser]TheFuzzy0ne[/eluser]
The reason I was asking is because I'm messing around with methods that allow you to pass parameters to libraries and models via the autoload.php file via arrays. I've currently implemented my changes around that line of code, when it would probably be a lot easier to just get rid of it so it makes more sense.

If the $libraries variable is an array, then $object_name (and possibly $params) should not be passed to the library loader IMHO. I'd like to add an extra test in there, so that the first parameter to the library() loader method can be something like this:
Code:
$autoload['libraries'] = array(
    'session',
    array(
        'my_lib',
        NULL,
        'new_name'
    ),
    array(
        'my_lib2',
        'some_arg'
    ), # And so on...
);

I'd also like to make the model loader method work in a similar fashion.

So in short I just needed to know that I was missing something, so I can get rid of that line in my overriding Loader methods.

Thanks for your input.




Theme © iAndrew 2016 - Forum software by © MyBB