public function actionCreate()
 {
     $model = new Mark();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['update', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function search($params)
 {
     $query = Mark::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => new \yii\data\Sort(['attributes' => ['name', 'id']])]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'text', $this->text]);
     return $dataProvider;
 }
Example #3
0
 public function getMark()
 {
     return $this->hasOne(Mark::className(), ['id' => 'mark_id']);
 }
Example #4
0
        </div>
        <div class="col-lg-4 col-xs-4">
            <?php 
echo $form->field($model, 'sort')->textInput();
?>
        </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]);
Example #5
0
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>