【问题标题】:Set relations on GroceryCRUD with Codeigniter使用 Codeigniter 在 Grocery CRUD 中设置关系
【发布时间】:2015-11-25 18:50:51
【问题描述】:

我正在使用 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 时,我收到此错误

【问题讨论】:

  • 你能调试一下je3b51b9f是什么以及来自哪里吗?
  • @Tpojka 嗨,我没有任何名为 je3b51b9f 的表,所以我认为是由 GroceryCRUD 模型库创建的临时表

标签: php codeigniter grocery-crud


【解决方案1】:

基于documentation

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

设置关系 1-n 数据库关系。这将自动创建一个 字段的下拉列表并显示字段的实际名称和 不仅仅是列表的主键

这意味着,它将显示表中除主键之外的字段(并且您正在尝试显示Patient 中不存在的字段patients)。

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

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

【讨论】:

    【解决方案2】:
    $crud->set_relation('idpatients', 'patients', 'name');
    

    这将创建一个带有来自您的表患者的患者姓名的下拉列表

    您的问题是“患者”,您的患者表中不存在此列,用于更改视图名称:

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

    对不起我的英语

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-19
      • 1970-01-01
      • 1970-01-01
      • 2011-11-15
      • 1970-01-01
      相关资源
      最近更新 更多