Controller sali
public function add() { if($this->request->is('post')) { $this->Hall->create(); if($this->Hall->save($this->request->data)) { $id = $this->Hall->id; $this->Seat->create(); $rzedy = $this->request->data('Hall.count_rows'); $miejsca = $this->request->data('Hall.count_seats'); $ilosczapisow= 0; for($i = 1 ; $i <= $rzedy ; $i++) { for($j = 1 ; $j <= $miejsca ; $j++) { $this->Seat->set('num_rown',$rzedy); $this->Seat->set('num_seat',$miejsca); $this->Seat->set('Halls_id',$id); $this->Seat->set('status',1); if($this->Seat->save()) $ilosczapisow ++; if($i != $rzedy || $j != $miejsca) $this->Seat->create(); } } $this->Flash->success(' OK '); $this->redirect('test/'.$id); } else { $this->Flash->error('Error'); } } } // Funkcja do edycji miejsc public function test($id = null) { $this->set('seats',$hall_seat); { if($this->Seat->saveAll($this->data)) { $this->Flash->success('Data saved'); $this->redirect('test/'.$id); } else $this->Flash->error('Error'); }
Widok test
foreach($seats as $seat) { if($seat['Seat']['status'] == 1 ) "checked")); else }
Baza danych wygląda nast:
Halls (id,name,count_rows,count_seat),
Seats(id,num_rown,num_seat,Halls_id,status) gdzie
'className' => 'Halls', 'foreignKey' => 'Halls_id',)
Jestem dopiero początkujący w tym temacie ,więc miłą widziana wyrozumiałość jeśli to będzie jakaś trywialna rzecz.