/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'admin' page. * @param integer $id the ID of the model to be deleted */ public function actionDelete($id) { $model = $this->loadModel($id); $model->excluida = 1; $conditions = 'tamanho_sabor_id = ' . $model->id; $sabor = PizzaTamanhoSabor::model()->find($conditions); if (empty($sabor)) { $model->delete(); } else { $model->save(); } // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!isset($_GET['ajax'])) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index')); } }
public function afterSave() { $retorno = parent::afterSave(); if (!$this->isNewRecord) { return $retorno; } foreach ($this->_sabores as $sabor) { $modelPTS = new PizzaTamanhoSabor(); $modelPTS->tamanho_sabor_id = $sabor; $modelPTS->pizza_id = $this->id; $modelPTS->save(); } if (!empty($this->_adicionais)) { foreach ($this->_adicionais as $adicional) { $modelPTA = new PizzaTamanhoAdicional(); $modelPTA->tamanho_adicional_id = $adicional; $modelPTA->pizza_id = $this->id; $modelPTA->save(); } } return $retorno; }