/** * @return \yii\db\ActiveQuery */ public function getEAttributesRelation() { return $this->hasMany(ProductAttribute::className(), ['id' => 'attribute_id'])->viaTable('{{%product_type_attributes}}', ['product_type_id' => 'id']); }
/** * Finds the ProductAttribute model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return ProductAttribute the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = ProductAttribute::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<div class="product-type-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'parent_id')->dropDownList(ArrayHelper::map(ProductType::find()->asArray()->orderBy('name')->all(), 'id', 'name'), ['prompt' => '']); ?> <?php echo $form->field($model, 'eAttributes')->widget(Select2::classname(), ['data' => ArrayHelper::map(ProductAttribute::find()->asArray()->orderBy('name')->all(), 'id', 'presentation'), 'options' => ['multiple' => true]]); ?> <?php echo $form->field($model, 'options')->widget(Select2::classname(), ['data' => ArrayHelper::map(ProductOption::find()->asArray()->orderBy('name')->all(), 'id', 'presentation'), 'options' => ['multiple' => true]]); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Module::t('module', 'Create') : Module::t('module', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-primary' : 'btn btn-success']); ?> </div> <?php ActiveForm::end(); ?>