Issue
I have two tables, cars and locations; I want loadModel Car in LocationsController and I want, when I add location, for it to automatically status column in Cars table registers unavailable into 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);
}
Solution
Remove this lines
App::import('model','Car');
$this->Car->write('Car.status', 'unavailable');
Following code you have to write
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.'));
}
Answered By - Sadikhasan Answer Checked By - Terry (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.