Docs: Massive Assignments
Like normal models, Active Record instances also enjoy the massive assignment feature. Using this feature, you can assign values to multiple attributes of an Active Record instance in a single PHP statement, like shown below. Do remember that only safe attributes can be massively assigned, though.
Docs: Safe Attributes
For this reason, a special validator aliased safe is provided so that you can declare an attribute to be safe without actually validating it. For example, the following rules declare that both title and description are safe attributes.
You have to do some sort of validation on your attribute, if you don't have any validation needs - define it as safe
.
public function rules()
{
return [
[['name'], 'safe'],
];
}
$model->load($_POST)
? – Shaverhttps://github.com/yiisoft/yii2/blob/master/framework/web/Request.php#L453
in an ordinary form there is probably (?) no difference but it is the Yii2-way of doing things. In case you have aapplication/json
request, there are differences. – Salbu