public function actionKitten($pid = 0) { if ($pid) { $parent = Category::model()->findByPk(intval($pid)); if (!$parent) { throw new CHttpException(404, "Раздела не существует"); } } else { $parent = new Category(); } $child = new Category(); $child->setAttributes($_POST["Category"]); $child->setParent($parent); if (!$child->save()) { Yii::app()->user->setFlash("error", $child->getErrorsString()); } $this->redirect("/moderator/catalog?edit={$parent->id}"); }
/** * @ignore */ public function addCategory(Category $cat) { $this->categories[$cat->getId()] = $cat; $cat->setParent($this); }