/** * Creates a new ItemProp model. * If creation is successful, the browser will be redirected to the 'view' page. * @param $categoryId * @return mixed */ public function actionCreate($categoryId) { $model = Kiwi::getItemProp(['category_id' => $categoryId]); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['category/index']); } else { return $this->render('create', ['model' => $model, 'category' => Kiwi::getCategory()->findOne($categoryId)]); } }
$fields[] = $form->field($model, 'sort')->textInput(); $fields[] = $form->field($model, 'status')->checkbox(); $fieldGroups[] = ['label' => 'Base Info', 'content' => implode('', $fields)]; $fields = []; $fields[] = $form->field($model, 'original_price')->textInput(['maxlength' => 10]); $fields[] = $form->field($model, 'price')->textInput(['maxlength' => 10]); $fields[] = $form->field($model, 'stock_qty')->textInput(); $fields[] = $form->field($model, 'min_sale_qty')->textInput(); $fields[] = $form->field($model, 'max_sale_qty')->textInput(); $fields[] = $form->field($model, 'weight')->textInput(['maxlength' => 10]); $fields[] = $form->field($model, 'shipping_fee')->textInput(['maxlength' => 10]); $fields[] = $form->field($model, 'is_free_shipping')->checkbox(); $fieldGroups[] = ['label' => 'Price & Stock', 'content' => implode('', $fields)]; $fields = []; $fields[] = $form->field($model, 'pictures')->widget(InputFile::className(), ['multiple' => true, 'template' => '<div class="input-group">{input}<span class="input-group-btn">{button}</span></div>', 'options' => ['class' => 'form-control'], 'buttonOptions' => ['class' => 'btn btn-default']]); $categories = \kiwi\Kiwi::getCategory()->find()->all(); $categories = ArrayHelper::map($categories, 'id', 'name'); $fields[] = $form->field($model, 'categoryIds')->widget(Select2::classname(), ['data' => $categories, 'language' => 'en', 'options' => ['placeholder' => 'Select a state ...'], 'options' => ['multiple' => true]]); $tags = \kiwi\Kiwi::getTag()->find()->all(); $tags = ArrayHelper::map($tags, 'id', 'name'); $fields[] = $form->field($model, 'tagIds')->widget(Select2::classname(), ['data' => $tags, 'language' => 'en', 'options' => ['placeholder' => 'Select a state ...'], 'options' => ['multiple' => true]]); $fieldGroups[] = ['label' => 'Picture & Category & Tag', 'content' => implode('', $fields)]; echo Tabs::widget(['items' => $fieldGroups]); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div>
public function treeModel() { return Kiwi::getCategory(); }