我使用了連接查詢,它連接了三張表employee,places和employee_places。連接查詢給了我所有結果,因爲我使用了find('all')。但在查看頁面中,我只想從員工表中顯示員工姓名 - 從下拉菜單中的地點表中放置姓名。 例如: - emp1-place1,emp2-place2等等。我應該在哪裏給查找字段名稱。 請看下面的代碼:使用find加入cakephp
$選項[ '連接'] =陣列( 陣列( '表'=> '僱員', '別名'=> 'EMP', '類型'=>'內 ' '條件'=>數組( 'emp.id = EmployeePlace.employee_id' ) ) 陣列( '表'=> '的地方', '別名'=> 'PL', ' '=''inner', 'conditions'=> array( 'pl.id = EmployeePlace.place_id' ) ) );
$ empTables = $ this-> Bill-> EmployeePlace-> find('all',$ options);
$ this-> set(compact('empTables'));
上面的查詢結果如下數組: -
陣列 ( [0] =>數組 ( [EmployeePlace] =>數組 ( [ID] => 1 [EMPLOYEE_ID] = > 1 [place_id] => 1 [日期] => 2011-02-02 )
[Employee] => Array
(
[id] => 1
[image] =>
[firstName] => Andy
[lastName] => Murray
[date_of_joining] => 2010-09-02
[date_of_leaving] => 2011-02-02
[date_of_birth] => 1991-08-10
[gender] => Male
[supervisor] => 0
[designation] => Manager
[user_id] => 0
)
[Place] => Array
(
[id] => 1
[placeName] => table-1
[section_id] => 1
[position] => Left
[seating_capacity] => 4
)
)
)
我只想從僱員名字 - placeName從下拉菜單中放置表格。我如何在find中使用條件來做到這一點。
模型中有虛擬字段可以幫助。 – 2011-02-08 11:46:27
如果你舉一個例子來說明上面的代碼會更好。 – 2011-02-08 11:53:12