/** * * @inheritdoc */ public function save($runValidation = true, $attributeNames = null) { $parent = null; if (isset($this->parent_id) && $this->parent_id) { $parent = Category::findOne((int) $this->parent_id); } if (!$parent) { $parent = Category::findOne(1); } if (!$parent) { throw new \yii\base\InvalidParamException(); } $this->appendTo($parent); try { return parent::save($runValidation, $attributeNames); } catch (yii\base\Exception $exc) { \Yii::$app->session->setFlash('crudMessage', $exc->getMessage()); } }