2015-08-31 22 views
2

我正在与codeigniter进行项目合作,这是我第一次使用GroceryCRUD,并且我需要让患者可以拥有任意数量的报告,我在我的数据库中有这样的报告。使用Codeigniter在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

任何帮助,将不胜感激修复它,我怎样才能申报的关系,所以当我添加一个新的报告,我可以从下拉框中选择患者或其他东西?

UPDATE

当我改变db_debug假我得到这个错误基于documentation

enter image description here

+0

你能调试什么是和在哪里'je3b51b9f'来自? – Tpojka

+0

@Tpojka嗨,我没有任何名为je3b51b9f的表,所以我认为是由GroceryCRUD模型库创建的临时表 –

回答

1

无效set_relation(字符串$ FIELD_NAME,串$ related_table ,string $ related_title_field [,mixed $ where [,string $ ord er_by]])

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

这意味着,它将从表中的其他然后主键显示字段(和你正在试图显示字段Patient这不是在本patients)。

解决您的问题 - 更换PatientName(或其他一些领域,其存在于patinets表):

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

这创造与患者的名字drowpdownList从表中的病人

你的问题是“病人”,这个专栏不存在你的餐桌上的病人,因为改变名字查看使用:

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

对不起,我的英语