/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Brands::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]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
use frontend\models\Brands; use frontend\models\Marketplace; use frontend\models\watches; /* @var $this yii\web\View */ /* @var $model frontend\models\Watches */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="watches-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'brands_id')->dropDownList(ArrayHelper::map(Brands::find()->all(), 'id', 'name'), ['prompt' => 'select brand', 'onchange' => ' $.post("/index.php/watches/lists?id=' . '"+$(this).val(),function(data){ $("select#watches-modelno").html(data); }); ']); ?> <?php echo $form->field($model, 'modelno')->textInput(); ?> <?php echo $form->field($model, 'marketplace_id')->dropDownList(ArrayHelper::map(marketplace::find()->all(), 'id', 'name'), ['prompt' => 'select marketplace']); ?> <?php
/** * @return \yii\db\ActiveQuery */ public function getBrand() { return $this->hasOne(Brands::className(), ['id' => 'brand_id']); }
/** * Finds the Brands model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Brands the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Brands::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }