使用Codeigniter在GroceryCRUD上设置关系

时间:2015-08-31 17:01:34

标签: php codeigniter grocery-crud

我正在使用codeigniter开发一个projecj,这是我第一次使用GroceryCRUD,我需要让患者可以拥有任意数量的报告,我在我的数据库中有这个。

enter image description here

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

我收到此错误

enter image description here

任何帮助都将被理解为修复它,我如何声明关系,所以当我添加新报告时,我可以从下拉框中选择患者?

更新

当我将db_debug更改为false时,我收到此错误

enter image description here

2 个答案:

答案 0 :(得分: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');

答案 1 :(得分:0)

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

这会创建一个drowpdownList,其中包含患者名单中患者的姓名

您的问题是“患者”,此栏目患者不存在此栏目,更改名称视图使用:

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

对不起我的英文

相关问题