简体   繁体   English

使用 Codeigniter 在 GroceryCRUD 上设置关系

[英]Set relations on GroceryCRUD with Codeigniter

I am working on a projecj with codeigniter, and it's my first time using GroceryCRUD, and I need to make that a patient can have any number of reports, I have this on my database.我正在使用 codeigniter 开发一个项目,这是我第一次使用 GroceryCRUD,我需要让患者可以拥有任意数量的报告,我的数据库中有这个。

在此处输入图片说明

Where idpatients is the foreign key.其中 idpatients 是外键。

I am using this on my controller我在我的控制器上使用这个

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);
}

And I get this error我得到这个错误

在此处输入图片说明

Any help would be appreciated to fix it, How can I declare the relationship so when I add a new report I can choose the patient from a dropdownbox or something?任何帮助修复它,我如何声明关系,以便在添加新报告时,我可以从下拉框或其他内容中选择患者?

UPDATE更新

When I change db_debug for false I get this error当我将 db_debug 更改为 false 时,我收到此错误

在此处输入图片说明

Based on documentation :基于文档

void set_relation( string $field_name , string $related_table, string $related_title_field [, mixed $where [, string $order_by ] ] ) void set_relation( 字符串 $field_name , 字符串 $related_table, 字符串 $related_title_field [, 混合 $where [, 字符串 $order_by ] ] )

Set a relation 1-n database relation.设置关系 1-n 数据库关系。 This will automatically create a dropdown list to the fields and show the actual name of the field and not just a primary key to the list .这将自动为字段创建一个下拉列表,并显示字段的实际名称,而不仅仅是列表的主键

Which means, it will display the field from the table other then primary key (and you are trying to display field Patient which is not present in patients ).这意味着,它将从表中显示的字段等则主键(和你想显示字段Patient这是不存在patients )。

Solution for your issue - replace Patient with Name (or some other field which is present in patinets table):您的问题的解决方案 - 将Patient替换为Name (或patinets表中存在的一些其他字段):

$crud->set_relation('idpatients','patients','Name');
$crud->set_relation('idpatients', 'patients', 'name');

This create a drowpdownList with the name of patients from your table patients这将使用表患者中的患者姓名创建一个下拉列表

Your problem is "Patient", this column not exist on your table patients, for change the name on view use:您的问题是“患者”,您的表患者中不存在此列,用于更改视图名称:

$crud->display_as('idpatients', 'Patient');

I'm sorry for my English我为我的英语感到抱歉

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM