Yii2, what the model parameter does in widget? -


echo select2::widget([     'model' => $vendormodel,     'attribute' => 'id',     'data' => $vendor,     'options' => ['placeholder' => 'select vendor ...'],     'pluginoptions' => [         'allowclear' => true     ], ]); 

the above select2 widget (and of widgets same) require model attribute, don't know model in widget, because if put other model object, works.

replaced model $usermodel doesn't relate vendor model @ , tried, , works.

echo select2::widget([     'model' => $usermodel,     'attribute' => 'id',     'data' => $vendor,     'options' => ['placeholder' => 'select vendor ...'],     'pluginoptions' => [         'allowclear' => true     ], ]); 

how should understand model?

select2 widget instance of yii2 input widget , renders input model attribute. useful forms create/update model. e.g. if actioncreate() should use new activerecord model instance widget 'model' attribute , attribute name want fill 'attribute'.

so in example trying set model id key $vendor list. models fit widget settings because have 'id'.

i believe need provide other attribute here called e.g. 'vendor_id'. notice $vendor list should have vendor ids keys , e.g. vendor names values.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -