Welcome Guest, Not a member yet? Register   Sign In
Using a library inside a library inside a foreach
#1

[eluser]skunkbad[/eluser]
I'm trying to load a library inside a library, inside a foreach, but I'm getting errors. Here's what I've got:

Code:
<?php
class Shipping
{
    public $options = array(
        'UPS',
        'USPS',
        'FedEx'
    );
    
    public $rates_array = array();

    public function get_rates($weight,$total)
    {

        $CI =& get_instance();

        foreach($this->options as $option)
        {
            $CI->load->library($option);
            $this->rates_array = array_merge( $CI->$option->get_rate( $weight, $total ) , $this->rates_array );
        }

        return $rates_array;
    }
}

and here is the error I am getting:

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: Checkout::$UPS

Filename: libraries/Shipping.php

Line Number: 20

and

Quote:Fatal error: Call to a member function get_rate() on a non-object in F:\wamp\www\community_cart\application\libraries\Shipping.php on line 20

You can see that I'm trying to use a $option variable in the call to get_rate() on line 20. I thought I saw another thread on doing this a couple weeks ago, but can't find it. What should I do?
#2

[eluser]skunkbad[/eluser]
I figured it out. I just needed to uncapitalize the name of the libraries being called.




Theme © iAndrew 2016 - Forum software by © MyBB