public function afterSave() { if ($this->isNewRecord) { $category_translation = new CategoryTranslation(); $category_translation->id_category = $this->id_category; $category_translation->name = $this->name; $category_translation->id_language = 1; $category_translation->save(); } }
/** * 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) { $category_translations = CategoryTranslation::model()->findAllByAttributes(array('id_category' => $id)); foreach ($category_translations as $category_translation) { $category_translation->delete(); } $model = $this->loadModel($id); // if (count($model->categories) > 0) // foreach ($model->categories as $data) // $data->delete(); // var_dump($data->id_category); $model->delete(); // 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('admin')); } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return CategoryTranslation the loaded model * @throws CHttpException */ public function loadModel($id) { $model = CategoryTranslation::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }