2014-05-13 5 views
0

일부 CodeIgniter 모델을 작성하려고하지만 알아 내지 못하는 문제가 있습니다. 변수 범위와 관련이 있을지 모르지만 확실하지 않습니다. 당신이 볼 수 있듯이PHP 정적 메서드 변수 범위

public function review($token) 
{ 
     $order = Order_model::get_by_token($token, BC_EXT_TYPE_ID, 'Order_product'); 

     print_r($order); 
} 

, 나는 get_by_token()라는 정적 메소드를 호출하고 있습니다 :

내가 인수로 $token 값을 취 내 컨트롤러의 방법이있다. 다음은 그 기능에 대한 코드는 다음과 같습니다

public static function get_by_token($unique_token, $ext_type_id = NULL, $join_class = NULL, $details = TRUE){ 

        $CI =& get_instance(); 

     $where = array(
       "unique_token" => $unique_token, 
       "deleted" => 0, 
       "ext_type_id" => $ext_type_id 
     ); 

     $CI->db->where($where); 
     $query = $CI->db->get(static::$db_table); 
     $model = $query->row(0, get_called_class()); 

     self::get($model->id, null, null, 'Order_product'); 
} 

이 기능은 토큰을 기반으로 데이터베이스에서 검토의 ID를 가져온 다음 검토에 추가 데이터를 결합하는 또 다른 정적 메소드를 호출합니다. 당신이 볼 수 있듯이 달러 (A $)의 join_class가 제공되는 경우

public static function get($id = NULL, $ext_id = NULL, $ext_type_id = NULL, $join_class = NULL, $details = TRUE){ 

       $CI =& get_instance(); 

       $where = array(
         "deleted" => 0 
       ); 

       if(!is_null($id)){ 
         $where['id'] = $id; 
       } 
       elseif(!is_null($ext_type_id) && !is_null($ext_id)){ 
         $where['ext_id'] = $ext_id; 
         $where['ext_type_id'] = $ext_type_id; 
       } 

       $CI->db->where($where); 

       $query = $CI->db->get(static::$db_table); 
       $model = $query->row(0, get_called_class()); 

       if(!is_null($join_class)){ 
         $joins = $join_class::get($model->id, null, null, $details); 
         $join_property = explode('_', $join_class); 
         $join_property = $join_property[1].'s'; 
         $model->$join_property = array(); 
         foreach($joins as $join){ 
           $model->{$join_property}[] = $join; 
         } 

       } 

       return $model; 

} 

, 다른 정적 방법은 데이터를 결합 할 수 및 개체에 추가하기 위해 $의 join_class 호출됩니다 다음은 get() 기능입니다. 조인 클래스의 get() 방법은 여기에 있습니다 :

public static function get($primary_id, $secondary_id = NULL, $external_type_id = NULL, $details = TRUE){ 

     $CI =& get_instance(); 

     $where = array(
       static::$primary_column => $primary_id, 
       'deleted'=>0 
     ); 

     if(!is_null($secondary_id)){ 
       $where[static::$secondary_column] = $secondary_id; 
     } 

     if(!is_null($external_type_id)){ 
       $where['ext_type_id'] = $external_type_id; 
     } 

     $CI->db->where($where); 
     $query = $CI->db->get(static::$db_table); 

     $result = array(); 

     foreach($query->result(get_called_class()) as $row){ 

       if($details){ 
         $secondary_model = static::$secondary_model; 
         $secondary_column = static::$secondary_column; 
         $object = $secondary_model::get($row->$secondary_column); 
         $row->details = $object; 
       } 

       $result[] = $row; 
     } 

     return $result; 

} 

오전 데 문제는 그냥 처음의 get() 함수가 반환하기 전에 $ 모델의 값을 인쇄하는 경우, 올바르게 모든 데이터를 나에게 보여주고 있다는 것입니다 나는 기대. 그러나 리뷰 메서드에서 $ order 변수를 출력 할 때 아무 것도 얻을 수 없습니다. 즉 빈 응답입니다.

나는 왜 가치가 변하는 지 모르겠다. 그러나 나는 그것이 아마도 가변적 인 범위로 내려다보고 있다고 생각한다. 누구 아이디어가 있습니까? 당신의 get_by_token 기능에

답변

0

, 이것을 사용 :

return self::get($model->id, null, null, 'Order_product');