2011-09-12 2 views
2

set_relation()을 확장하는 방법을 알고있는 사람이 있습니까? 여기 Codeigniter 식료품 점은 set_relation() 함수를 확장합니까?

코드 출력이 드롭 다운에있는 모든 도시를 보여줍니다 sample table

$crud->set_relation('officeCode','offices','city'); 

식료품 침전물 직원 및 사무실 테이블의 예에 아이디어, 기본,하지만 난 정도까지 set_relation()을 모든 도시를 필터링 할 원하는 상태가 드롭 다운으로 표시 되나요?

예를 들어 나는 모든 도시를 아리조나 주에 표시하고 싶습니다. 식료 잡화를 사용하기 전에 누구나이 작업을 수행합니까?

참고 예 :

Grocery Crud 나는 당신이 찾고있을거야 믿을

답변

1

난 당신이 필요하다고 생각 :

function employees_management() 
{ 
    $crud = new grocery_CRUD(); 

    $crud->set_theme('datatables'); 
    $crud->set_table('employees'); 
    // add this line 
    $crud->callback_edit_field('officeCode',array($this,'_call_back_offices')); 
    $crud->callback_add_field('officeCode',array($this,'_call_back_offices')); 

    $crud->display_as('officeCode','Office City'); 
    $crud->set_subject('Employee'); 

    $crud->set_relation('officeCode','offices','city'); 

    $output = $crud->render(); 

    $this->_example_output($output); 
} 

function _call_back_offices() 
{ 
    $this->load->model('user_model'); // your model 
    $data = $this->user_model->getYou('offices','officeCode, city', "state = '".$this->session->userdata('state')."'"); // iam using session here 
    $hasil ='<select name="officeCode">'; 
    foreach($data as $x) 
    { 
     $hasil .='<option value="'.$x->officeCode.'">'.$x->city.'</option>'; 
    } 
    return $hasil.'</select>'; 
} 

example user_model code: 

function getYou($tabel,$field = '*', $cond ='') 
{ 
    $this->db->select($field); 
    $this->db->from($tabel); 
    if(!empty($cond)) $this->db->where($cond); 
    return $this->db->get()->result(); 
} 
1

가 여기에있다 ->은 http://www.grocerycrud.com/crud/function_name/set_model

이 원하는 방식으로 식료품 CRUD의 기능을 확장 할 수 있습니다 . 나는 내 자신의 사용자 지정 기능을 만들기 위해 실제로 모험하지는 않았지만, 그렇게하는 것이 좋습니다.

3
$crud->set_relation('officeCode','offices','city',array('country' => 'Arizona')); 

이 버전 v.1.2에 관해서는 잘 작동 이상

내가 아는
4

내 대답은 영업 이익에 어떤 어떤 일 아마 전혀 사용 지금,하지만 나는 자신의 set_relation 문제에 대한 영감을 얻기 위해이 게시물을보고있는 많은 사람들이 있다고 생각합니다. 나는 (set_relation의 4 PARAM()가 가능하게되었다 때 나도 몰라 Idham에 공평하게.)이에 더 간단한 솔루션을 제안

... 
$state = "AZ"; // or however you get the state you want to filter by 
$crud->set_relation('officeCode','offices','city', 'officeCode IN (SELECT officeCode FROM offices WHERE state='.$state.')'); 
... 

짜잔를! True grocery_CRUD awesomeness!

관련 문제