Ich habe drei Tabellen in meiner Datenbank:
Stations(id, name, adresse, tel, fax, modified, ...)
Prices(id, station_id, petrol_id, value, created)
Petrols(id, name)
Ich gebe nun mit prices/add/2 z.B. die PReise der tankstelle mit der ID 2 ein - so ist das Ziel.
- Code: Alles auswählen
- function add($id = null) {
if (!empty($this->data)) {
$this->Price->create();
if ($this->Price->save($this->data)) {
$this->Session->setFlash(__('The price has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The price could not be saved. Please, try again.', true));
}
}
$stations = $this->Price->Station->find('list');
$petrols = $this->Price->Petrol->find('list');
$this->data['Price']['active'] = 1;
$station_id = $this->params['id'];
$this->data['Price']['station_id'] = $station_id;
$this->set(compact('stations', 'petrols'));
}
Das Feld für die "station_id" habe ich dabei nicht mehr im View enthalten.
Diese soll ja über die URL mit übergeben werden.
Nun habe ich gedacht, dass dies mit dem obigen Code funktioniert. Leider überträgt er weder die active=1 in die DB, noch die station_id als 2 (in dem Bsp.)