You should setAttributes
of your model from $_POST
, so Yii will reassign model values to form components, just like with saving models, but without save:
public function someAction()
{
// load model somewhere
$model = $this->_loadModel();
if($_POST['modelName'])
{
$model->setAttributes($_POST['modelName']);
}
$this->render('someView', ['model' => $model]);
}
EDIT:
After comments I noticed that you have your model with getYears
method, which Yii uses as getter for attribute years
, as explained in getters and setters tutorial. You should rename it for example getYearRanges
. And ensure you have years
attribute in your model to hold current years
value, and have rule as in HarryFink answer.