/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Brend::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; }
/** * Finds the Brend model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Brend the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Brend::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getBrend() { return $this->hasOne(Brend::className(), ['id' => 'brend_id']); }
<div class="items-form"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'cat_id')->dropDownList(ArrayHelper::map(Category::find()->all(), 'id', 'name'), ['prompt' => '-- Выберите--'])->label('Категирия. <a href="/category/create"> Создать</a>'); ?> <?php echo $form->field($model, 'brend_id')->dropDownList(ArrayHelper::map(Brend::find()->all(), 'id', 'name'), ['prompt' => '-- Выберите--'])->label('Производиетель звукоснимателя. <a href="/brend/create"> Создать</a>'); ?> <?php echo $form->field($model, 'strings')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'anker')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'form')->textInput(['maxlength' => true]); ?> <?php