我有一個名爲'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