我有两张桌子,车和位置;我想在LocationsController
中加载loadModel Car,当我添加位置时,我希望它能自动将状态栏中的列表寄存器置于locationsController中:
public function add($car_id) {
if ($this->request->is('post')) {
$this->Location->create();
if ($this->Location->save($this->request->data)) {
$this->Session->setFlash(__('The location has been saved.'));
return $this->redirect(array('action' => 'index'));
App::import('model','Car');
$this->Car->write('Car.status', 'unavailable');
} else {
$this->Session->setFlash(__('The location could not be saved. Please, try again.'));
}
}
$users = $this->Location->User->find('list');
$agencies = $this->Location->Agency->find('list');
/*$cars = $this->Location->Car->find('list');*/
$this->set(compact('agencies'));
$this->set('car_id', $car_id);
}
答案 0 :(得分:0)
删除此行
App::import('model','Car');
$this->Car->write('Car.status', 'unavailable');
以下代码你必须写
if ($this->Location->save($this->request->data)) {
$this->Session->setFlash(__('The location has been saved.'));
$this->loadModel("Car");
$this->Car->id=$car_id;
$this->Car->saveField("status","unavailable");
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The location could not be saved. Please, try again.'));
}