0
我在数据库中的下一个表:CakePHP的显示第二模型关联名,而不是ID
- 电梯
- 车辆
- 厂商
电梯属于关联车辆
车辆belongsTo制造商
制造商的hasMany车辆
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');
甲PRINTSCREEN:
所以我需要的是显示,而不是制造商ID的制造商名称。 在每一个模型$ displayField被设置为正确的值
谢谢你的答案,但它不工作。 – Andrei 2013-02-23 17:56:29