2011-09-12 16 views
2

set_relation()の拡張方法を知っている人はいますか?ここでCodeigniter Grocery Crudはset_relation()関数を拡張しますか?

はアイデア、食料品CRUDの従業員やオフィスのテーブルの例でベースsample table

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

は、コードの出力は、ドロップダウンリスト内のすべての都市が表示されますが、私はある程度set_relation()をして、すべての都市をフィルタリングするために必要です状態がドロップダウンに表示されますか?

たとえば、私はアリゾナ州のすべての都市をドロップダウンで表示したいと思います。食料雑貨を使用する前に誰でもこれをしましたか?

参考例:

Grocery Crud私はあなたが探していることになります信じられ

答えて

1

:私は私の応答は時代遅れ、いくつか何とOPにおそらく役に立たないことを知っているバージョンV.1.2用以降

1

がここにある - >はhttp://www.grocerycrud.com/crud/function_name/set_model

これは、あなたが望む方法で、食料品のCRUDの機能を拡張できるようになります。 私は実際に自分のカスタム機能を作成するつもりはありませんでしたが、それはやりたいことです。

私はあなたがこの必要があると思う
3
$crud->set_relation('officeCode','offices','city',array('country' => 'Arizona')); 

を今、私は自分のset_relationの問題にインスピレーションを与えてこのポストを見ているかもしれない多くの人がいると思います。私は(set_relationの第四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.')'); 
... 

出来上がりを!真の食料品!CRUD awesomeness!

4

これは正常に動作

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(); 
} 
関連する問題