public function search($params)
 {
     $query = Cellars::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'owner_id' => $this->owner_id, 'created_at' => $this->created_at, 'default_cellar_loc_id' => $this->default_cellar_loc_id]);
     $query->andFilterWhere(['like', 'cellar_name', $this->cellar_name]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Cellars::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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, 'owner_id' => $this->owner_id, 'created_at' => $this->created_at, 'default_cellar_loc_id' => $this->default_cellar_loc_id]);
     $query->andFilterWhere(['like', 'cellar_name', $this->cellar_name]);
     return $dataProvider;
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCellar()
 {
     return $this->hasOne(Cellars::className(), ['id' => 'cellar_id']);
 }
Exemple #4
0
<?php

use app\models\Cellars;
use app\models\Wines;
use app\models\Locations;
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\Cellarwines $model
 * @var yii\widgets\ActiveForm $form
 */
?>

<div class="cellarwines-form">

    <?php 
$form = ActiveForm::begin(['type' => ActiveForm::TYPE_HORIZONTAL]);
echo Form::widget(['model' => $model, 'form' => $form, 'columns' => 1, 'attributes' => ['cellar_id' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => ArrayHelper::map(Cellars::find()->orderBy('cellar_name')->asArray()->all(), 'id', 'cellar_name')], 'wine_id' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => Wines::getListing()], 'quantity' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Quantity...']], 'cellar_loc_id' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => ArrayHelper::map(Locations::find()->orderBy('loc_name')->asArray()->all(), 'id', 'loc_name')], 'rating' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Rating...']], 'created_at' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Created At...']], 'updated_at' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Updated At...']], 'cost' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Cost...', 'maxlength' => 10]]]]);
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>
 /**
  * Finds the Cellars model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Cellars the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Cellars::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }