Witam!
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_5I aktualnie tak wyglądają metody :
metoda odp. za edycje wydarzenia function edit($id = null)
{
$this->Event->id = $id;
if (empty($this->data)) { $this->data = $this->Event->read();
} else {
if($this->FileHandler->upload('Event', 'poster', md5($id) , 'posters/')) {
$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')); $this->redirect(array('action' => 'view', $id)); }
}
}
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
$db_band = $this->Event->Band->find('first', array( 'Band.name' => $band,
)
));
// if a genre was found
// save the genre id
$data[] = $db_band['Band']['id'];
} else {
// create a new genre
$save = array('Band'=>array
( '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();
}
}
}
}
}
return array('Band' => $data); }
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!