base\Model load()

load() public method

Populates the model with input data.

This method provides a convenient shortcut for:

if (isset($_POST['FormName'])) {
    $model->attributes = $_POST['FormName'];
    if ($model->save()) {
        // handle success
    }
}

which, with load() can be written as:

if ($model->load($_POST) && $model->save()) {
    // handle success
}

load() gets the 'FormName' from the model's formName() method (which you may override), unless the $formName parameter is given. If the form name is empty, load() populates the model with the whole of $data, instead of $data['FormName'].

Note, that the data being populated is subject to the safety check by setAttributes().

public boolean load ( $data, $formName = null )
$data array

The data array to load, typically $_POST or $_GET.

$formName string

The form name to use to load the data into the model. If not set, formName() is used.

return boolean

Whether load() found the expected form in $data.

doc_Yii
2016-10-30 16:51:53
Comments
Leave a Comment

Please login to continue.