/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Wineries::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['winery_name' => SORT_ASC]]]); $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, 'default_appellation_id' => $this->default_appellation_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'winery_name', $this->winery_name])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'proprietor_name', $this->proprietor_name])->andFilterWhere(['like', 'winemaker_name', $this->winemaker_name])->andFilterWhere(['like', 'website', $this->website])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
<?php use app\models\Wineries; use app\models\Appellations; use app\models\Varietals; use yii\helpers\Html; use yii\helpers\ArrayHelper; use kartik\widgets\ActiveForm; use kartik\widgets\Select2; use kartik\builder\Form; use kartik\datecontrol\DateControl; /** * @var yii\web\View $this * @var app\models\Wines $model * @var yii\widgets\ActiveForm $form */ ?> <div class="wines-form"> <?php $form = ActiveForm::begin(['type' => ActiveForm::TYPE_HORIZONTAL]); echo Form::widget(['model' => $model, 'form' => $form, 'columns' => 1, 'attributes' => ['upc_barcode' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Upc Barcode...', 'maxlength' => 30]], 'wine_name' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Wine Name...', 'maxlength' => 45]], 'winery_id' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => ArrayHelper::map(Wineries::find()->orderBy('winery_name')->asArray()->all(), 'id', 'winery_name')], 'appellation_id' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => ArrayHelper::map(Appellations::find()->orderBy('app_name')->asArray()->all(), 'id', 'app_name')], 'wine_year' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Wine Year...', 'maxlength' => 4]], 'wine_varietal_id' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => ArrayHelper::map(Varietals::find()->orderBy('varietal_name')->asArray()->all(), 'id', 'varietal_name')], 'bottle_size' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Bottle Size...', 'maxlength' => 15]], 'bottle_size' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => Yii::$app->params['bottle_sizes']], 'overall_rating' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Overall Rating...']], 'created_at' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Created At...']], 'updated_at' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Updated At...']], 'description' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Description...', 'maxlength' => 255]]]]); echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ActiveForm::end(); ?> </div>
* @var app\models\WinesSearch $searchModel */ $this->title = 'Wines'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="wines-index"> <div class="page-header"> <h1><?php echo Html::encode($this->title); ?> </h1> </div> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php /* echo Html::a('Create Wines', ['create'], ['class' => 'btn btn-success'])*/ ?> </p> <?php Pjax::begin(); echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'pjax' => true, 'columns' => [['attribute' => 'winery_id', 'header' => 'Winery', 'value' => 'winery.winery_name', 'width' => '170px', 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(Wineries::find()->orderBy('winery_name')->asArray()->all(), 'id', 'winery_name'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true]], 'filterInputOptions' => ['placeholder' => 'Any Winery']], ['attribute' => 'wine_year', 'value' => 'wine_year', 'hAlign' => GridView::ALIGN_CENTER, 'width' => '90px'], ['attribute' => 'varietal_name', 'value' => 'wineVarietal.varietal_name', 'width' => '175px'], 'wine_name', ['attribute' => 'appellation_id', 'header' => 'Appellation', 'value' => 'appellation.app_name', 'width' => '200px', 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(Appellations::find()->orderBy('app_name')->asArray()->all(), 'id', 'app_name'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true]], 'filterInputOptions' => ['placeholder' => 'Any appellation']], ['attribute' => 'bottle_size', 'value' => 'bottle_size', 'hAlign' => GridView::ALIGN_CENTER, 'width' => '90px'], ['attribute' => 'overall_rating', 'value' => 'overall_rating', 'hAlign' => GridView::ALIGN_CENTER, 'width' => '100px'], ['class' => 'kartik\\grid\\ActionColumn', 'width' => '70px', 'buttons' => ['update' => function ($url, $model) { return Html::a('<span class="glyphicon glyphicon-pencil"></span>', Yii::$app->urlManager->createUrl(['wines/view', 'id' => $model->id, 'edit' => 't']), ['title' => Yii::t('yii', 'Edit')]); }]]], 'responsive' => true, 'hover' => true, 'condensed' => true, 'floatHeader' => true, 'panel' => ['heading' => '<h3 class="panel-title"><i class="glyphicon glyphicon-th-list"></i> ' . Html::encode($this->title) . ' </h3>', 'type' => 'info', 'before' => Html::a('<i class="glyphicon glyphicon-plus"></i> Add', ['create'], ['class' => 'btn btn-success']), 'after' => Html::a('<i class="glyphicon glyphicon-repeat"></i> Reset List', ['index'], ['class' => 'btn btn-info']), 'showFooter' => false]]); Pjax::end(); ?> </div>
/** * @return \yii\db\ActiveQuery */ public function getWinery() { return $this->hasOne(Wineries::className(), ['id' => 'winery_id']); }
/** * Finds the Wineries model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Wineries the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Wineries::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<div class="wines-form"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> <?php echo $form->field($model, 'upc_barcode')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'wine_name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'winery_id')->dropDownList(ArrayHelper::map(Wineries::find()->all(), 'id', 'winery_name')); ?> <?php echo $form->field($model, 'appellation_id')->dropDownList(ArrayHelper::map(Appellations::find()->all(), 'id', 'appellation')); ?> <?php echo $form->field($model, 'wine_year')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'wine_varietal_id')->dropDownList(ArrayHelper::map(Varietals::find()->all(), 'id', 'name')); ?> <?php
/** * @return \yii\db\ActiveQuery */ public function getWineries() { return $this->hasMany(Wineries::className(), ['default_appellation_id' => 'id']); }