$model->load() how to ignore rules

Hey guys,

$model->load() will not populate attributes unless rules are set, and this makes perfect sense when dealing with data where you know your schema. However, can this be turned off when you don’t know your schema?

For instance we’re simply using a Model to build a dynamic form that is generated by the end user. When these are filled we don’t care about validation as these elements are simply passed to another server that does this for us. To make it simple : we don’t know the rules.

Is there a way to populate attributes without rules to accomplish this? Something along the lines of ["*", "safe"]

PS: We would rather not simply manipulate the $_POST because we have some business logic attached to our models.

Model::load() only parses the data from $_POST and populates the model using Model::setAttributes().

If you want to bypass the checking whether attributes are safe, you can call this method with the second parameter set to false:

$model->setAttributes($_POST['FormName'], false);

You can also override the load() method to achieve the same.

Yet this checking is here for a reason so be sure that you know well what’s going on in your code when departing from common practices.

Thanks!! That works well. And yes it’s ok if we handle unsafe variables for this.