public function actionCreate() { $model = new Category(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['update', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Category::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false, 'sort' => new \yii\data\Sort(['attributes' => ['name']])]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id]); $query->andFilterWhere(['like', 'name', $this->name]); $query->andFilterWhere(['like', 'text', $this->text]); return $dataProvider; }
public function getCategories() { return $this->hasMany(Category::className(), ['id' => 'category_id'])->viaTable('{{%autocatalog_model_to_category}}', ['model_id' => 'id']); }
use pistol88\gallery\widgets\Gallery; use kartik\select2\Select2; ?> <div class="category-form"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> <?php echo $form->field($model, 'name')->textInput(); ?> <?php echo $form->field($model, 'parent_id')->widget(Select2::classname(), ['data' => Category::buildTextTree(null, 1, [$model->id]), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите категорию ...'], 'pluginOptions' => ['allowClear' => true]]); ?> <?php echo $form->field($model, 'sort')->textInput(); ?> <?php echo $form->field($model, 'text')->textArea(); ?> <?php echo Gallery::widget(['model' => $model]); ?> <div class="form-group">
</div> </div> <div class="row"> <div class="col-lg-6 col-xs-6"> <?php echo $form->field($model, 'category_id')->widget(Select2::classname(), ['data' => Category::buildTextTree(), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите категорию ...'], 'pluginOptions' => ['allowClear' => true]]); ?> <?php echo $form->field($model, 'mark_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(Mark::find()->all(), 'id', 'name'), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите марку ...'], 'pluginOptions' => ['allowClear' => true]]); ?> </div> <div class="col-lg-6 col-xs-6"> <?php echo $form->field($model, 'category_ids')->label('Прочие категории')->widget(Select2::classname(), ['data' => Category::buildTextTree(), 'language' => 'ru', 'options' => ['multiple' => true, 'placeholder' => 'Доп. категории ...'], 'pluginOptions' => ['allowClear' => true]]); ?> </div> </div> <?php echo $form->field($model, 'text')->textArea(); ?> <?php echo Gallery::widget(['model' => $model]); ?> <div class="form-group autocatalog-control"> <?php echo Html::submitButton($model->isNewRecord ? 'Добавить' : 'Обновить', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
use yii\helpers\ArrayHelper; use yii\helpers\Html; use yii\helpers\Url; use pistol88\autocatalog\models\ModelOption; use pistol88\autocatalog\models\Category; use pistol88\autocatalog\models\Mark; use kartik\export\ExportMenu; $this->title = 'Модели'; $this->params['breadcrumbs'][] = $this->title; \pistol88\autocatalog\assets\BackendAsset::register($this); ?> <div class="model-index"> <div class="row"> <div class="col-md-2"> <?php echo Html::a('Добавить модель', ['create'], ['class' => 'btn btn-success']); ?> </div> </div> <?php echo \kartik\grid\GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'export' => false, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'id', 'filter' => false, 'options' => ['style' => 'width: 55px;']], 'name', 'code', ['attribute' => 'images', 'format' => 'images', 'filter' => false, 'content' => function ($image) { if ($image = $image->getImage()->getUrl('50x50')) { return "<img src=\"{$image}\" class=\"thumb\" />"; } }], ['attribute' => 'category_id', 'filter' => Html::activeDropDownList($searchModel, 'category_id', Category::buildTextTree(), ['class' => 'form-control', 'prompt' => 'Категория']), 'value' => 'category.name'], ['attribute' => 'mark_id', 'filter' => Html::activeDropDownList($searchModel, 'mark_id', ArrayHelper::map(Mark::find()->all(), 'id', 'name'), ['class' => 'form-control', 'prompt' => 'Марка']), 'value' => 'mark.name'], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}', 'buttonOptions' => ['class' => 'btn btn-default'], 'options' => ['style' => 'width: 125px;']]]]); ?> </div>
public function getParent() { return $this->hasOne(Category::className(), ['id' => 'parent_id']); }
use pistol88\autocatalog\models\Category; $this->title = 'Категории'; $this->params['breadcrumbs'][] = $this->title; \pistol88\autocatalog\assets\BackendAsset::register($this); ?> <div class="category-index"> <div class="row"> <div class="col-md-2"> <?php echo Html::a('Создать категорию', ['create'], ['class' => 'btn btn-success']); ?> </div> <div class="col-md-4"> </div> </div> <br style="clear: both;"></div> <br style="clear: both;"> <?php echo \kartik\grid\GridView::widget(['export' => false, 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'id', 'filter' => false, 'options' => ['style' => 'width: 55px;']], 'name', ['attribute' => 'image', 'format' => 'image', 'filter' => false, 'content' => function ($image) { if ($image = $image->getImage()->getUrl('50x50')) { return "<img src=\"{$image}\" class=\"thumb\" />"; } }], ['attribute' => 'parent_id', 'filter' => Html::activeDropDownList($searchModel, 'parent_id', Category::buildTextTree(), ['class' => 'form-control', 'prompt' => 'Категория']), 'value' => 'parent.name'], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}', 'buttonOptions' => ['class' => 'btn btn-default'], 'options' => ['style' => 'width: 125px;']]]]); ?> </div>