public function beforeSave($insert) { if (parent::beforeSave($insert)) { $model = new AssignRole(); if ($this->parent_id == NULL) { $this->parents = $this->id . '-'; $model->save(); } else { $pparents = $model->findOne($this->parent_id)->parents; $this->parents = $pparents . $this->id . '-'; $model->save(); } return true; } return false; }
/** * Creates a new AssignRole model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new AssignRole(); if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->parent_id == NULL) { $model->parents = $model->id . '-'; } else { $model->parents = $model->findOne($model->parent_id)->parents . $model->id . '-'; } if ($model->save()) { return $this->redirect(['view', 'id' => $model->id]); } } else { return $this->render('create', ['model' => $model]); } }