2

を拡張する方法を知っている人はいset_relation()ますか?

これは、Grocery Crudの従業員とオフィスのテーブルの例に基づいたアイデアですサンプルテーブル

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

コード出力ではドロップダウンにすべての都市がset_relation()表示されますが、州ごとにすべての都市をフィルタリングしてドロップダウンに表示するように拡張したいですか?

たとえば、アリゾナ州のすべての都市をドロップダウンで表示したいのですが、食料品のクラッドを使用する前にこれを行った人はいますか?

参考例:

食料品クラッド

4

4 に答える 4

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

これはバージョンv.1.2以降で正常に機能します

于 2012-04-19T21:12:48.567 に答える
1

あなたが探しているものはここにあると思います --> http://www.grocerycrud.com/crud/function_name/set_model

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

于 2011-09-17T14:36:39.527 に答える
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();
}
于 2011-10-28T05:04:29.473 に答える