2014-07-09 1 views
0

나는 이상 main_images 함수에 나는 성공적인 main_product 기능에서 일부 데이터를 얻기 위해 노력하고얻기 변수 하나의 방법에서 다른 - CodeIgniter의

public function main_product($p_id) { 


    $this->db->select('p.*'); 
    $this->db->from('products_main as p'); 
    $this->db->where('p.product_id',$p_id); 
    $this->db->where('p.status','Active'); 
    $query = $this->db->get(); 

    if ($query->num_rows() > 0): 
     return $query->result(); 
     foreach($query->result() as $row): 

      $product_tag = $row->product_tag; 
      $product_id = $row->product_id; 
      $name_family = $row->name_family; 

     $this->main_images($product_id, $product_tag, $name_family); 
     endforeach;   
    else: 
     $this->session->set_flashdata('message', 'The main product query was unsuccessful.'); 
    endif;  
} 


public function main_images($product_id, $product_tag, $name_family) { 
    //run query 
    $this->db->select('im.*'); 
    $this->db->from('images_main as im'); 
    $this->db->where('im.pro_img_id',$p_id); 
    /*$this->db->where('im.img_tag',$product_tag); 
    $this->db->where('im.img_family',$name_family);*/ 
    $this->db->order_by('img_order', 'desc'); 
    $query = $this->db->get(); 

    if ($query->num_rows() > 0): 
     return $query->result(); 
    else: 
     $this->session->set_flashdata('message', 'The new image query was unsuccessful.'); 
    endif;  

} 

내 CodeIgniter의 모델의 두 가지 방법/기능을 가지고 있습니다. 나는 모델에서와 같이 변수를 통해 전달할 수 있다고 생각했지만 성공하지 못했습니다. 주위를 둘러 보았을 때 나는 이것과 비슷한 것의 몇 가지 예를 발견했으나 작동시키기에는 실패했다.

답변

1

main_images 함수에서 $this->db->where('im.pro_img_id',$p_id);은 이되어야합니다. $p_id은 정의되어 있지 않습니다.

더욱이 은 모델에서 모든 데이터베이스 상호 작용을 유지할 것을 제안합니다. 컨트롤러는 모델에서보기로 또는 사용자에서 모델로만 데이터를 전달해야합니다.

+0

변경 사항을 작성했으나 "메시지 : Shop_model :: main_images()에 대한 인수 1이 누락되었습니다. 26 행의 /application/controllers/mainpro.php에서 호출되며"인수 2와 동일합니다. 그리고 3 인자. ​​또한 이것은 오타에 대해 유감스러운 모델이다. – Amir

+0

Mainpro 컨트롤러에서 오류가 발생했습니다. 파일을 확인하십시오. –

+0

$ this-> shop_model-> main_images()이 줄은 논쟁의 여지가 없지만 (위의 코드에 따라) 모델에 인수를 전달했기 때문에 생각했습니다. 컨트롤러에 있습니까? – Amir

관련 문제