参考:http ://www.grocerycrud.com/documentation/options_functions/set_model
我有 2 个这样的表:
[tblFitnessClasses] id uid 标题 描述 位置
[tblFitnessClassDateTimes] owner_uid startDate endDate startTime endTime 天数重复
本质上,我希望表格最终是这样的:
(uid - hidden) | Title | Description | Location | Start Date | End Date | Start Time | End Time | Days | Reccurence
Swim Lesson Level 1 Gym 05/04/2012 NULL 12:30 1:30 Mon,Wed,Fri 2
在我的主控制器的一部分中,我有这个:
function fitnessSchedule()
{
$this->config->set_item('url_suffix', '');
$crud = new grocery_CRUD();
$crud->set_table('tblFitnessClasses');
$this->load->model('schedule_model');
$this->schedule_model->join_table('tblFitnessClasses','tblFitnessClassDateTimes');
$crud->columns('title','description','location','startEventDate','endEventDate','startTime', 'endTime', 'days', 'recurrence', 'finalDate);
$crud->display_as('title','Event')
->display_as('description','Description')
->display_as('location','Location')
->display_as('startEventDate','Start Date')
->display_as('endEventDate','End Date')
->display_as('startTime','Start Time')
->display_as('endTime','End Time');
$crud->required_fields('title','location');
$crud->set_subject('Event');
$output = $crud->render();
$this->_example_output($output);
}
在我的模型中,我有这个:
<?php
class schedule_model extends CI_Model
{
public function join_table($table1,$table2)
{
$this->output->enable_profiler(TRUE);//Turns on CI debugging
$this->db->select("*");
$this->db->from($table1);
$this->db->join($table2, $table1.".uid". "=".$table2.".owner_uid"); // Join classes and class date times by UID
$results = $this->db->get()->result();
return $results;
}
}
?>
当我运行此代码时,我得到一个包含所有必填字段的表,但 table2 (tblFitnessClassDateTimes) 中的字段缺少所有信息。这些字段不填充其数据。除此之外,如果我选择编辑表格,它只会编辑able1(tblFitnessClassses)