public function actionCreate($type = null, $dropDown = false) { $model = new Category(); $model->type = $type; $avatar = CmgFile::loadFile($model->avatar, 'Avatar'); $model->setScenario('create'); if ($model->load(Yii::$app->request->post(), 'Category') && $model->validate()) { if (CategoryService::create($model, $avatar)) { return $this->redirect($this->returnUrl); } } return $this->render('@cmsgears/module-core/admin/views/category/create', ['model' => $model, 'avatar' => $avatar, 'dropDown' => $dropDown]); }
public function actionCreate() { $model = new Category(); $model->setScenario("create"); if ($model->load(Yii::$app->request->post(), "Category") && $model->validate()) { if (CategoryService::create($model)) { return AjaxUtil::generateSuccess(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::MESSAGE_REQUEST), $model); } } // Generate Errors $errors = AjaxUtil::generateErrorMessage($model); // Trigger Ajax Failure return AjaxUtil::generateFailure(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_REQUEST), $errors); }
/** * @return array - Category associated with parent */ public function getCategories() { return $this->hasMany(Category::className(), ['id' => 'categoryId'])->viaTable(CoreTables::TABLE_MODEL_CATEGORY, ['parentId' => 'id'], function ($query) { $modelCategory = CoreTables::TABLE_MODEL_CATEGORY; $query->onCondition(["{$modelCategory}.parentType" => $this->categoryType]); }); }
/** * @param string $type * @return Category */ public static function findByType($type) { return Category::findByType($type); }
/** * @return Category - associated category */ public function getCategory() { return $this->hasOne(Category::className(), ['id' => 'categoryId']); }
/** * @param integer $categoryName - category name * @return array - an array having value as key and name as value for given category name. */ public static function getValueNameMapByCategoryName($categoryName) { $category = Category::findByName($categoryName); $options = $category->options; $optionsMap = array(); foreach ($options as $option) { $optionsMap[$option->value] = $option->name; } return $optionsMap; }
/** * @return array - list of immediate child categories */ public function getCategories() { return $this->hasMany(Category::className(), ['parentId' => 'id']); }