질문 Q #12681
Call to a member function get_by_od_id() on array 에러 관련
에반스 2015-12-05 00:32:09
아래와 같은 에러에 대해 문의 드립니다. 
Call to a member function get_by_od_id() on array

컨트롤러
	function test(){
		$this->load->model('cart');
		$this->load->model("Orders");
		$order = $this->orders->get_by_od_id("1512049909");
		
		$dat = $this->cart->get_total_shipping_cost("1512049909", "ev_cart_order");
		
	}

위에서 첫번째 get_by_od_id 함수는 실행 잘 됩니다.

cart 모델
class Cart extends MY_MODEL {
    var $isLogged;
    var $ss_id;
    var $free_shipping;
    function __construct() {
        parent::__construct();
        if(!isset($this->session->userdata['isLogged'])){
            $this->isLogged = FALSE;
        }else{
            $this->isLogged = TRUE;
        }
        if(!$this->session->userdata["ss_id"]) $this->session->set_userdata("ss_id", md5($this->input->server('REMOTE_USER').time()));
        $this->ss_id = $this->session->userdata["ss_id"];
        $free = array("some"=>50000, "dome"=>200000);
        if($this->session->userdata['level'] == "dome") $this->free_shipping = 200000;
        elseif($this->session->userdata['level'] == "kiup") $this->free_shipping = 0;
        else $this->free_shipping = 50000;

        if($this->session->userdata['language'] <> "korean"){
            $this->op_weight = "op_weight_en as op_weight";
            $this->free_shipping = 0;
        }else{
            $this->op_weight = "op_weight";
        }


    }    
function get_total_shipping_cost($ss_id="",$table="ev_cart"){
    	if($table != "ev_cart"){
    		
    		$order = $this->orders->get_by_od_id($ss_id);
    		$level = $this->customers->get_level($order['mb_id']);
    		$amount = $order['od_amount'] - $order['od_shipping_cost'];
    		$box = $this->box_qty("", true, $ss_id, $table);
    		$language = ($order['od_type'] == "oversea")?"english":"korean";
    	}else{
    		if(!$ss_id) $ss_id = $this->session->userdata['ss_id'];
    		
    		$order = $this->session->userdata['order'];
    		$level = $this->session->userdata['level'];
    		$amount = $order['od_amount'];
    		$box = $this->box_qty($ss_id, true);
    		$language = $this->session->userdata('language');
    	}

		$tCost = 0;

    	if($order['od_country_receipt'] <> "KR"){
    		$costs = $this->ems_cost($order['od_country_receipt'], true, "english", $box);
    		$box = array_merge($costs);
    		foreach ($box['ems_sm_box'] as $b) {
    			$tCost += $b['cost'] * $b['qty'];
    		}
    		foreach ($box['ems_lg_box'] as $b) {
    			$tCost += $b['cost'] * $b['qty'];
    		}
    		$box['total_shipping_cost'] = $tCost;

    	}else{
    		$long_cost = $this->long_distence_cost($order['od_zipcode_receipt'], $box);

    		if( $this->check_free_shipping($level,$amount) ){
    			$sm_cost = 0;
    		}else{
    			$sm_cost = 2500;
    		}
			foreach ($box['sm_weight'] as $b) {
				$tCost += ($b['qty'] * $sm_cost) + ($b['qty'] * $long_cost) ;
			}
			foreach ($box['lg_weight'] as $b) {
				$tCost += ($b['qty'] * $sm_cost) + ($b['qty'] * $long_cost) ;
			}
		
    		$box['total_shipping_cost'] = $tCost;
    	}
    	return $box;
    }
}


위 에서 31번줄에 get_by_od_id 에서 글제목과 같은 에러가 납니다. 이유가 뭔지 모르겠네요. 이전에는 잘 되다가 갑자기 되지 않네요.

혹시 원인을 아시는 분 계십니까?


 
답변 2
#1 한대승(불의회상) 2015-12-05 12:01:02
cart 모델 로드 하기전에 orders 모델 로드가 되어 있지 않아 생긴 에러 입니다.
cart 생성자 함수에서 미리 orders 모델을 로드 하면 해결 됩니다.
#2 에반스 2015-12-07 14:39:25
아하! 그걸 미쳐 생각 못했습니다. 정말, 감사합니다. ㅠ_ㅠ