我是cakephp的新手。我正在使用查詢構建器從cakephp查詢構建器中使用連接從兩個表中獲取詳細信息。但是,我正在編寫的查詢僅從一個表中獲取細節。需要幫助以從其他表中獲取數據。加入查詢僅從一張表中檢索數據cakephp 3
這是我的代碼通過連接兩個表來獲取數據:
public function edit($id = null) {
$events_table = TableRegistry::get('Events');
$events = $events_table->find('all')
->hydrate(false)
->join([
'CourseType'=> [
'table' => 'coursetype',
'type' => 'LEFT',
'conditions' => 'Events.type = CourseType.coursetype_id',
]
])->where(['Events.id' => $id]);
$event = $events->toArray();
$this->set('event', $event);
}
結果我從事件表中只獲得詳細信息。但我需要從coursetype也數據。任何幫助表示讚賞。謝謝。
試試這個https://stackoverflow.com/a/845519/4514250。可能是有幫助的。 –
這是cakephp 3.x還是cakephp 2.x? –