我在数据库中有下一个表:
- 电梯
- 车辆
- 制造商
电梯属于车辆
车辆属于制造商
制造商有很多车辆
LiftsController.php 添加方法:
public function add() {
if ($this->request->is('post')) {
$this->Lift->create();
$this->request->data['Lift']['user_id'] = $this->Auth->user('id');
if ($this->Lift->save($this->request->data)) {
$this->Session->setFlash(__('The lift has been saved'));
$this->redirect(array('action' => 'my_lifts'));
} else {
$this->Session->setFlash(__('The lift could not be saved. Please, try again.'));
}
}
$vehicles = $this->Lift->Vehicle->find('all', array('fields' => array('id', 'model', 'manufacturer_id')));
$towns = $this->Lift->TownFrom->find('list', array('order' => 'county ASC, name ASC', 'fields' => array('id', 'name', 'county')));
$this->set(compact('users', 'vehicles', 'towns'));
}
LiftsController.php 添加视图:
echo $this->Form->input('vehicle_id');
打印屏幕:
所以我需要的是显示制造商 ID 而不是制造商名称。在每个模型中,$displayField 都设置为正确的值