0

我在数据库中有下一个表:

  • 电梯
  • 车辆
  • 制造商

电梯属于车辆

车辆属于制造商

制造商有很多车辆

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 都设置为正确的值

4

2 回答 2

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')));
于 2014-03-11T00:26:15.330 回答
0

尝试改变:

echo $this->Form->input('vehicle_id');

echo $this->Form->input('Vehicle');
于 2013-02-22T17:14:28.703 回答