저는 현재 작업중인 MVC 프로젝트의 모델을 개발 중입니다. 나는 그것을 처리 할 수있는 각 방법에 대한 작업 또는 단일 기능에 대한 여러 기능을 가지고 더 나은지 궁금 했어. 여러 경우를 처리단일 대 복수 함수
public function get($identifiers = null, $limit = null, $offset = null)
{
if ($identifiers != null) {
if (is_array($identifiers)) {
$this->db->where($identifiers);
} else {
$this->db->where($this->_key, $identifiers);
$method = 'row'.($this->_return_array ? '_array' : '');
return $this->db->get($this->_table)->$method();
}
}
if ($limit != null) {
$this->db->limit($limit, $offset || null);
}
if (!count($this->db->ar_orderby)) {
$this->db->order_by($this->_order);
}
$method = 'result'.($this->_return_array ? '_array' : '');
return $this->db->get($this->_table)->$method();
}
또는 등등
get($id) {}
get_where($where) {}
get_all() {}
및 별도의 기능을 가지고 예를 들어, 더 나은 뭔가를하는 것입니다.
"깨끗한 코드"와 같은 것을 원하면 두 번째 버전이 더 좋습니다. – Philipp