2017-05-08 81 views
1

例如,我有兩個表('intervalosHorarios'和'entregas'[1_n]),我想顯示來自特定'intervalosHorarios'id的'entregas'列表。我嘗試了以下,但它沒有奏效。獲取具有特定ID的元素列表

enter image description here

控制器列表

public function entregas_lista($idCarga) { 

     $crud = new grocery_CRUD(); 

     $datos = array(
      'title' => "entregas", // En la vista 'header' tendré una variable $title 
      'username' => "Administrador" 
     ); 

     $this->load->view('commons/header', $datos); 

     //Quitamos los botones de añadir y quitar 
     $crud->unset_add(); 
     $crud->unset_edit(); 

     $crud->set_language("spanish"); 
     $crud->set_theme('bootstrap'); 
     $crud->set_table('entregas'); 



     $crud->where('idCarga =', $idCarga); 



     $crud->display_as('idCarga', 'Nº Entrega'); 
     $crud->set_subject('Carga/Descarga'); 
     $crud->set_relation('idCarga', 'intervalosHorarios', 'intervaloHorario'); 

     $crud->columns('fechaCita', 'horaCita', 'numeroEntrega', 'cliente', 'Origen', 'Destino', 'cargaPrevista', 'entregaPrevista', 'accion', 'estado'); 




     $output = $crud->render(); 




     $this->_example_output($output); 


     //--------------- Cargo la vista 'commons/footer.php' -------------/
     $this->load->view('commons/footer'); 
    } 




    function _example_output($output = null) { 
     $this->load->view('example', (array) $output); 
    } 
+0

交表圖像 –

+0

表貼@Parvez – Jose

回答

0

如果這一切您在方法內部寫的代碼,問題是,你是不是查詢數據庫。

請參閱官方文檔here

你需要寫你的方法是這樣的:

公共職能entregas_lista($ idCarga){

$crud = new grocery_CRUD();  
$crud->set_table('entregas'); 
$crud->where('idCarga =', $idCarga); 

$result = $crud->render(); 

return $result; 

}

+0

我已經發布了完整的方法和實施工作,但我無法通過ID – Jose

+0

來篩選:功能_example_output($輸出= NULL)把這個函數:$ this->負荷 - > view('example',['data'=> $ output]); 。然後轉到視圖在開始寫:var_dump($ data); exit; 。看看你是否有任何數據。 –

+0

哼哼..我想我不是很好解釋。我正在使用食品雜貨庫,最好不要觸摸它的代碼。但問題是,當我點擊'間隔Horario'它向我展示所有'entregas'項目,我想只顯示'entregas'項目,包括在'intervaloHorario' - @Florin Popescu – Jose

0

解決,我只是修改了此行:

$crud->set_relation('idCarga', 'intervalosHorarios', 'intervaloHorario'); 

發送至:

$crud->set_relation('idIntervaloHorario', 'intervalosHorarios', 'intervaloHorario'); 

然後我已經擦除了數據庫,它的工作完美。

無論如何。

+0

呃...看起來就像有一個持續存在的問題,它只顯示第一個元素添加,而不是其他的... – Jose