2013-04-21 3 views
0

codeigniter 페이지 매김 클래스를 사용하고 있으며이 코드에 고정되어 있습니다! 다음 코드는 employees 테이블에서 전체 열을 읽지 만 내 쿼리에는 조인이 포함되어 있습니다. 구성 설정을 사용하여 내 자신의 쿼리를 어떻게 실행할 것인지 잘 모르겠습니다.맞춤법 검사기 코드 지정자 페이지 지정 클래스

$config['per_page'] = 20; 
$view_data['view_data'] = $this->db->get('employees', $config['per_page'], $this->uri->segment(3)); 

내 자신의 쿼리 :

$this->db->select('emp.code as emp_code,emp.fname as emp_fname,emp.lname as emp_lname,emp.faname as emp_faname,emp.awcc_phone as emp_phone,emp.awcc_email as emp_email,position as position,dep.title as department'); 
$this->db->from('employees as emp'); 
$this->db->join('departments as dep','dep.code=emp.department_code'); 
$this->db->where('emp.status = 1'); 
$employees_list = $this->db->get(); 
return $employees_list; 

답변

0

당신의 접근 방식은 완전히 잘못된 것입니다. 컨트롤러에서 는 사용

에 대한 this 자습서를 참조하십시오

function getEmployees($limit = 10 , $offset = 0) 
{ 
    $select = array(
        'emp.code as emp_code', 
        'emp.fname as emp_fname', 
        'emp.lname as emp_lname', 
        'emp.faname as emp_faname', 
        'emp.awcc_phone as emp_phone', 
        'emp.awcc_email as emp_email', 
        'position as position', 
        'dep.title as department' 
    ); 

    $this->db->select($select); 
    $this->db->from('employees as emp'); 
    $this->db->join('departments as dep','dep.code=emp.department_code'); 
    $this->db->where('emp.status',1); 
    $this->db->limit($offset , $limit); 
    return $this->db->get()->result(); 
} 

$this->load->model('mymodel'); 
$config['per_page']  = 20; 
$view_data['view_data'] = $this->mymodel->getEmployees($config['per_page'], $this->uri->segment(3)); 

Modle 기능처럼 할