gpt4 book ai didi

php - 使用 Active Record 和 GroceryCrud 在 CodeIgniter 中加入表

转载 作者:行者123 更新时间:2023-11-29 07:00:30 25 4
gpt4 key购买 nike

引用:http://www.grocerycrud.com/documentation/options_functions/set_model

我有 2 个这样的表:

[tblFitnessClasses] id uid title description location

[tblFitnessClassDateTimes] owner_uid startDate endDate startTime endTime days recurrence

基本上我希望表格像这样结束:

(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

在我的主 Controller 的一部分,我有这个:

     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)

enter image description here enter image description here

最佳答案

您以错误的方式加载模型。事实上,你甚至没有加载一个!您只是在创建 grocery_CRUD 的新实例,而不是您编写的模型。

$this->load->model('schedule_model');
$this->schedule_model->join_table('tblFitnessClasses','tblFitnessClassDateTimes');

关于php - 使用 Active Record 和 GroceryCrud 在 CodeIgniter 中加入表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10450671/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com