使用 Codeigniter 在 GroceryCRUD 上设置关系

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 时,出现此错误

基于documentation

void set_relation( string $field_name , string $related_table, string $related_title_field [, mixed $where [, string $order_by ] ] )

Set a relation 1-n database relation. 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.

这意味着,它将显示来自 table 的字段而不是主键(并且您正在尝试显示 patients 中不存在的字段 Patient)。

您的问题的解决方案 - 将 Patient 替换为 Name(或 patinets table 中存在的其他字段):

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

这将创建一个下拉列表,其中包含您的 table 个患者

中的患者姓名

您的问题是 "Patient",此列在您的 table 患者中不存在,要在视图中更改名称,请使用:

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

对不起我的英文