Chcąc dodać do swojego skryptu możliwość tagowania (akurat w moim skrypcie odpowiednikiem tagów i postów są zespoły (tagi) przypisywane do wydarzeń (postów) ) skorzystałem z tego artykułu :
http://www.jamesfairhurst.co.uk/posts/view...lication_part_5
I aktualnie tak wyglądają metody :
metoda odp. za edycje wydarzenia
function edit($id = null) { $this->Event->id = $id; $this->data = $this->Event->read(); } else { { $imageData = $this->FileHandler->getLastUploadInfo(); $this->params['data']['Event']['poster_extension'] = $imageData['extension']; } $this->data['Band'] = $this->_parse_genres($this->data['Event']['bands']); if ($this->Event->save($this->data)) { $this->Session->setFlash('Wydarzenie zostało zaktualizowane.', 'default', array('class' => 'success')); } } }
Funkcja _parse_genres()
function _parse_genres($bands = null) { // variable to save genre data array // explode the genres sepearated by a comma // if the explode array is not empty // loop through exploded genres foreach($explode as $band) { // remove leading/trailing spaces // if the genre is not empty // find the genre in the db 'Band.name' => $band, ) )); // if a genre was found // save the genre id $data[] = $db_band['Band']['id']; } else { // create a new genre 'name' => $band, )); // create model // has to be done when adding multiple items in a row $this->Event->Band->create(); // save the new genre $saveOK = $this->Event->Band->save($save); // if save was successful if($saveOK) { // last insert id $data[] = $this->Event->Band->getLastInsertID(); } } } } } }
Wszystko działa jak trzeba jednak pojawiła się pewna komplikacja - kiedy zapisuje zmiany ( edit() ), edytowane wydarzenie zostaje zapisane jednak w bazie pojawia się nowe wydarzenie będące kopią tego edytowanego (tylko id jest inne). Czy ktoś ma może pomysł co jest nie tak z tymi metodami ? Niestety mnie nie udało się znaleźć niczego, co wyglądało by na błąd
Pozdrawiam i z góry dzięki!