2012-01-28 5 views
0

세그먼트를 모델에 보내기 전에 모범 사례가 무엇인지 궁금합니다. 예를 들어세그먼트에 모델을 보내는 가장 좋은 방법은 무엇입니까?

:

내 컨트롤러 내가 잘 설명 바랍니다

public function query_detail($segment1) 
{ 
//what are the best practice before I send the segment1 to the Model? 
    $this->load->model('model'); 
    $this->model->query($segment1); 
    ...... 
} 

에 BASE_URL/컨트롤러/query_detail/segment1

에서 segment1를 가져옵니다. 도와 주셔서 감사합니다.

+0

미안하지만,별로 의미가 없습니다. – Chamilyan

답변

1

모델에 데이터를 보내어 해당 데이터로 삽입 또는 업데이트를 실행하는 경우 가장 좋은 방법은 사용자가 제출할 때 입력의 유효성을 검사하는 것입니다. 그런 다음 코드 데이터를 바운드 데이터로 사용할 때 데이터 정리를 수행하므로 삽입을 실행할 수 있습니다.

# This would be in your model...not your controller 
function store_data($post_data) { 
    $sql = "INSERT INTO some_table set (fld1, fld2, fld3) VALUES (?, ?, ?)"; 
    $binds = array($post_data['fld1'], $post_data['fld2'], $post_data['fld3']); 
    $this-db->query($sql, $binds); 
} 

들어오는 양식의 입력 태그 이름이 모두 데이터베이스 열 이름과 일치하면 간단하게 이렇게 할 수 있습니다.

# This would be in your model...not your controller 
function store_data($post_data) { 
    $sql = "INSERT INTO some_table set (fld1, fld2, fld3) VALUES (?, ?, ?)"; 
    $binds = array($post_data); 
    $this-db->query($sql, $binds); 
} 

또는이;

# This would be in your model...not your controller 
# Using ActiveRecord 
function store_data($post_data) { 
    $this->db->insert('some_table', $post_data); 
} 
+0

정확히 내가 필요한 것. Skittles 감사합니다. – Rouge

관련 문제