我有一个名为'events'的对象,它是通过$ data ['events'] =函数创建的(该函数从事件表和其他使用活动记录的信息中抽取信息)。CodeIgniter多维对象 - ActiveRecord
事件对象的样子:
Array
(
[0] => stdClass Object
(
[id] => 2
[course_name] => Course 3
[course_description] => Course
[course_price] => 995
[supplier_name] => Supplier 3
[location_country_code] => GB
[location_country] => United Kingdom
[location_city] => London
[venue_name] => Venue 2
[venue_address] => 2 Street
[venue_postcode] => EC2M 7PQ
[venue_city] => London
[venue_county] =>
[venue_country] => United Kingdom
[venue_locality] =>
[event_type] => Materials Only
[event_status] => Confirmed
[course_id] => 2
[event_duration] => 3
[event_start_date] => 2013-09-12
[event_date_added] => 2013-02-26 14:36:06
[event_status_id] => 2
[event_type_id] => 4
[tutor_id] => 0
[tutor_confirmed] => 0
[event_featured] => 0
[event_push] => 0
[event_active] => 0
[invigilator_id] => 0
[event_discount] =>
[event_max_delegates] => 16
[location_id] => 1
[venue_id] => 1
[supplier_id] => 2
)
[1] => stdClass Object
(
[id] => 1
[course_name] => Course Name
[course_description] => Course Description
[course_price] => 995
[supplier_name] => Supplier 1
[location_country_code] => GB
[location_country] => United Kingdom
[location_city] => London
[venue_name] => Venue Name
[venue_address] => Street
[venue_postcode] => EC2M 7PQ
[venue_city] => London
[venue_county] =>
[venue_country] => United Kingdom
[venue_locality] =>
[event_type] => Private Venue
[event_status] => Provisional
[course_id] => 1
[event_duration] => 3
[event_start_date] => 2013-11-13
[event_date_added] => 2013-02-26 09:56:17
[event_status_id] => 1
[event_type_id] => 3
[tutor_id] => 0
[tutor_confirmed] => 0
[event_featured] => 0
[event_push] => 0
[event_active] => 0
[invigilator_id] => 0
[event_discount] => 395
[event_max_delegates] => 16
[location_id] => 1
[venue_id] => 1
[supplier_id] => 1
)
)
我想使用桥通过连接到该事件的委托增加下使用ActiveRecord每一行按键“代表”一个嵌套的对象,那拉通过比较该表中的'event_id'和'delegate_id列'表'events_delegates_bridge'。 本质上使物体看起来像这样:
Array
(
[0] => stdClass Object
(
[id] => 2
[course_name] => Course 3
[delegates] => Array
(
[0] => stdClass Object
(
[id] => 1
[name] => Joe Bloggs
)
[1] => stdClass Object
(
[id] => 2
[name] => Joe Smith
)
[3] => stdClass Object
(
[id] => 3
[name] => Jane Doe
)
)
[course_description] => Course
[course_price] => 995
[supplier_name] => Supplier 3
[location_country_code] => GB
[location_country] => United Kingdom
[location_city] => London
[venue_name] => Venue 2
[venue_address] => 2 Street
[venue_postcode] => EC2M 7PQ
[venue_city] => London
[venue_county] =>
[venue_country] => United Kingdom
[venue_locality] =>
[event_type] => Materials Only
[event_status] => Confirmed
[course_id] => 2
[event_duration] => 3
[event_start_date] => 2013-09-12
[event_date_added] => 2013-02-26 14:36:06
[event_status_id] => 2
[event_type_id] => 4
[tutor_id] => 0
[tutor_confirmed] => 0
[event_featured] => 0
[event_push] => 0
[event_active] => 0
[invigilator_id] => 0
[event_discount] =>
[event_max_delegates] => 16
[location_id] => 1
[venue_id] => 1
[supplier_id] => 2
)
)
任何想法如何更好地实现这一目标?谢谢。
事件模型 类Event_Model延伸CI_Model {
public function get_events() {
$this->db->select('*');
$this->db->from('courses');
$this->db->from('suppliers');
$this->db->from('locations');
$this->db->from('venues');
$this->db->from('event_type');
$this->db->from('event_status');
$this->db->join('events', 'events.course_id = courses.id AND events.supplier_id = suppliers.id AND events.location_id = locations.id AND events.venue_id = venues.id AND events.event_type_id = event_type.id AND events.event_status_id = event_status.id', 'inner');
$this->db->order_by('events.event_start_date', 'asc');
$query = $this->db->get();
return $query->result();
}
}
控制板控制器 $数据[ '事件'] = $这个 - > event_model-> get_events();
代表模型 我已经创建了这个来获取委托数据。你认为它可以用来将正确的代表添加到事件对象吗?
class Delegate_Model extends CI_Model {
public function get_delegates() {
$this->db->select('*');
$this->db->from('delegates');
$this->db->from('events_delegates_bridge');
$this->join('delegates', 'delegates.id = events_delegates_bridge.delegate_id', 'inner');
$query = $this->db->get();
return $query->result();
}
}
刚刚测试过,它显示一个空白页。
我想使用活动记录吗? – 2013-02-27 15:47:28
如果需要,您可以用它们的活动记录等价物替换' - > query()'位。 – 2013-02-27 15:51:58
我已经编辑了我的问题,在仪表板控制器中添加了事件模型和$ data对象,这样您就可以看到我如何通过事件进行操作了。我将如何去整合你所解释的内容?我是CodeIgniter的新手。 – 2013-02-27 16:08:58