How to set attribute labels when using dynamic model in yii2 framework?
Here is my code below:
$model = DynamicModel::validateData(compact('name','shipping'), [
[['name','shipping'], 'required'],
]);
if ($model->hasErrors()) {
// validation fails
// }
} else {
//validation true
}
attributeLabels()is only a getter, not a setter. There was a (closed) issue on GitHub requesting such a feature; the comments suggest implementing your ownMyDynamicModelclass which allows for setting attribute labels. github.com/yiisoft/yii2/issues/6420