Is there a way to do a Model::load preventing that some fields are loaded without unset the vars

Is there a way that a Model::load($_POST) prevents the loading of some fields without unset the vars?

E.g.: If I have a model that have a ‘[font=“Courier New”]status[/font]’ field whose have a default rule in it so that, when a user is creating a record, its value would be 1.

On my scheme, 1 means ‘waiting for aproval’.

But, on my controller, I use


$model->load(Yii::$app->request->post())

.

If a bad dude sends me a POST requisition with the status field with the value of 10, then it will pass. And on my system, 10 means ‘ok’. And that is bad.

I think that you have two choices:

  1. Set manually status after massive assignment:



$model->load(Yii::$app->request->post());

$model->status = 0;



  1. Use scenario:

http://www.yiiframework.com/doc-2.0/guide-structure-models.html#scenarios