我有数据库中的下一个表:
提升所属车辆
车辆所属制造商
制造商拥有多辆车
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');
A printcreen:
所以我需要的是显示而不是制造商ID的制造商名称。 在每个模型中,$ displayField都设置为正确的值
答案 0 :(得分:0)
尝试更改:
echo $this->Form->input('vehicle_id');
要
echo $this->Form->input('Vehicle');
答案 1 :(得分:0)
更改强>
$vehicles = $this->Lift->Vehicle->find('all', array('fields' => array('id', 'model', 'manufacturer_id')));
要强>
$vehicles = $this->Lift->Vehicle->find('list', array('conditions' => array('Vehicle.user_id' => $this->Auth->user('id')), 'recursive' => 0, 'fields' => array('Vehicle.id', 'Vehicle.model', 'Manufacturer.title')));