/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Category(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (Yii::app()->params['server'] == CAlexHelper::DEVELOPMENT) { if (Yii::app()->request->isAjaxRequest) { if ($_POST['Category']['parentId'] == '') { $model = new Category(); $model->name = $_POST['Category']['name']; $model->alias = $_POST['Category']['alias']; if ($model->saveNode()) { echo 'success'; } } else { $parent = $this->loadModel($_POST['Category']['parentId']); $model = new Category(); $model->name = $_POST['Category']['name']; $model->alias = $_POST['Category']['alias']; if ($parent->append($model)) { $model->refresh(); echo 'success'; } } return; } } $this->render('create', array('model' => $model)); }
public function actionCreate() { $err = true; $this->breadcrumbs = array('Теги' => array('index'), 'Создать'); $model = new Category(); if (isset($_POST['Category'])) { $model->attributes = $_POST['Category']; if ($model->validate()) { if (!empty($model->parent_id)) { $parent = $this->loadModel($model->parent_id); if ($model->appendTo($parent)) { $model->refresh(); $err = false; } } else { if ($model->saveNode()) { $err = false; } } if ($err) { $this->addFlashMessage($model->errors, 'error'); } else { $this->redirect(Yii::app()->createAbsoluteUrl('/admin/tags')); } } else { $this->addFlashMessage($model->errors, 'error'); } } $this->render('_form', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Category(); //$model->enableBehavior('tree'); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Category'])) { $model->attributes = $_POST['Category']; if (!empty($_POST['Category']['parent_id'])) { $root = Category::model()->findByPk($_POST['Category']['parent_id']); $model->appendTo($root); } else { $model->saveNode(); } $this->redirect(array('view', 'id' => $model->id)); } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Category('create'); $action = 'category'; if (isset($_POST['Category'])) { //Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); $model->attributes = $_POST['Category']; $parent_node = $_POST['Category']['node']; if ($parent_node != 0) { $node = Category::model()->findByPk($parent_node); $model->appendTo($node); } if ($model->saveNode()) { $this->redirect(array('admin')); } } $this->render('create', array('model' => $model)); }
public function actionCreate() { $err = true; $model = new Category(); if (isset($_POST['Category'])) { $model->attributes = $_POST['Category']; if ($model->validate()) { if (!empty($model->parent_id)) { $parent = $this->loadModel($model->parent_id); if ($model->appendTo($parent)) { $model->refresh(); $err = false; } } else { if($model->saveNode() && $model->storeTypeAttributes(Yii::app()->getRequest()->getPost('attributes', []))){ $err = false; } } if ($err) { $this->addFlashMessage($model->errors,'error'); } else { $this->redirect(Yii::app()->createAbsoluteUrl('catalog/admin/default')); } } else { $this->addFlashMessage($model->errors,'error'); } } $this->render('_form', array('model' => $model)); }