public function search($params) { $query = Varietals::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 100]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'varietal_name', $this->varietal_name])->andFilterWhere(['like', 'common_flg', $this->common_flg])->andFilterWhere(['like', 'varietal_type', $this->varietal_type])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Varietals::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['common_flg' => SORT_DESC, '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]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'common_flg', $this->common_flg])->andFilterWhere(['like', 'varietal_type', $this->varietal_type])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
/** * Finds the Varietals model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Varietals the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Varietals::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<?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>
/** * @return \yii\db\ActiveQuery */ public function getWineVarietal() { return $this->hasOne(Varietals::className(), ['id' => 'wine_varietal_id']); }
?> <?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 echo $form->field($model, 'bottle_size')->dropDownList(Yii::$app->params['bottle_sizes']); ?> <?php echo $form->field($model, 'description')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'overall_rating')->textInput(); ?> <?php