![](/img/trans.png)
[英]CodeIgniter GroceryCrud set_relation same id in multiple tables
[英]Set relations on GroceryCRUD with Codeigniter
我正在使用 codeigniter 開發一個項目,這是我第一次使用 GroceryCRUD,我需要讓患者可以擁有任意數量的報告,我的數據庫中有這個。
其中 idpatients 是外鍵。
我在我的控制器上使用這個
public function reports()
{
$crud=$this->grocery_crud;
$crud->set_table('reports');
$crud->set_subject('Reports');
$crud->set_language('english');
$crud->set_relation('idpatients','patients','Patient');
$output=$crud->render();
$this->load->view('admin_reports', $output);
}
我得到這個錯誤
任何幫助修復它,我如何聲明關系,以便在添加新報告時,我可以從下拉框或其他內容中選擇患者?
更新
當我將 db_debug 更改為 false 時,我收到此錯誤
基於文檔:
void set_relation( 字符串 $field_name , 字符串 $related_table, 字符串 $related_title_field [, 混合 $where [, 字符串 $order_by ] ] )
設置關系 1-n 數據庫關系。 這將自動為字段創建一個下拉列表,並顯示字段的實際名稱,而不僅僅是列表的主鍵。
這意味着,它將從表中顯示的字段等則主鍵(和你想顯示字段Patient
這是不存在patients
)。
您的問題的解決方案 - 將Patient
替換為Name
(或patinets
表中存在的一些其他字段):
$crud->set_relation('idpatients','patients','Name');
$crud->set_relation('idpatients', 'patients', 'name');
這將使用表患者中的患者姓名創建一個下拉列表
您的問題是“患者”,您的表患者中不存在此列,用於更改視圖名稱:
$crud->display_as('idpatients', 'Patient');
我為我的英語感到抱歉
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.