/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Brood::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, 'date_create' => $this->date_create, 'date_update' => $this->date_update, 'breed_id' => $this->breed_id, 'common_status_id' => $this->common_status_id]); $query->andFilterWhere(['like', 'name', $this->name]); $query->andFilterWhere(['like', 'date', $this->date]); return $dataProvider; }
<?php echo $form->field($model, 'mother_link')->textInput(); ?> <?php echo $form->field($model, 'father_name')->textInput(); ?> <?php echo $form->field($model, 'father_link')->textInput(); ?> <?php echo $form->field($model, 'breed_id')->dropDownList(\app\models\Breed::getAll(), ['prompt' => Yii::t('app', '-- select breed --'), 'data-url' => '/pet/subcategory']); ?> <?php echo $form->field($model, 'brood_id')->dropDownList(\app\models\Brood::getAllWithDate($model->breed_id), ['prompt' => Yii::t('app', '-- select brood --')]); ?> <?php echo $form->field($model, 'pet_status_id')->dropDownList(\app\models\PetStatus::getAll()); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?>
/** * @return \yii\db\ActiveQuery */ public function getBrood() { return $this->hasOne(Brood::className(), ['breed_id' => 'id'])->orderBy('date desc'); }
/** * Finds the Brood model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Brood the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Brood::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getBrood() { return $this->hasOne(Brood::className(), ['id' => 'brood_id']); }
$this->params['breadcrumbs'][] = $this->title; ?> <div class="pet-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a(Yii::t('app', 'Create Pet'), ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'petImages', 'value' => function ($data) { if ($data->petImages) { return "<img src='/" . $data->petImages[0]->source_url . "' />"; } return "<img src='/' />"; }, 'format' => 'raw', 'contentOptions' => ['class' => 'grid-image'], 'filter' => false], 'name', 'date_create', 'date_update', ['attribute' => 'breed_id', 'filter' => \app\models\Breed::getAll(), 'value' => 'brood.breed.name'], ['attribute' => 'brood_id', 'filter' => \app\models\Brood::getAllWithDate(), 'value' => function ($data) { return $data->brood->name . " " . $data->brood->date; }], ['attribute' => 'pet_status_id', 'filter' => \app\models\PetStatus::getAll(), "value" => "petStatus.name"], ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
public function actionSubcategory($id) { $subcategories = Brood::getAllWithDate($id); $response = "<option value=''>" . Yii::t('app', '-- select brood --') . "</option>"; foreach ($subcategories as $key => $subcategoryName) { $response .= "<option value='{$key}'>{$subcategoryName}</option>"; } return $response; }