Batch Update in Contoller

I would like to batch update all student names in the Controller.

$student = new ActiveDataProvider([

			'query' => Student::find()->


				orderBy('id ASC'),






foreach ($student as $id){

			$studentname = $student[$id]->name;

			$student[$id]->name = substr($studentname,0,100);


I’m getting error - “Cannot use object of type yii\data\ActiveDataProvider as array”

Please help.

Edited content to format the code (first post was by phone )

There are many errors in your code.

At first you do not need a data provider.

Data provider are used for grid/list and are not necessary to just update data

$student = Student::find()->where(['status'=>'0'])->orderBy('id ASC')->all();

Then your foreach is in any case wrong

Foreach statement give you directly the item, you need the index only if you decide to modify the original array. But since the var holding the object always contain a reference to the instance of the object, therefore if you modify the object you do not update the array

foreach ($student as $id=>$row){

    $studentname = $row->name;

    $row->name = substr($studentname,0,100);


If you tell me what you want to achieve I can give you some more suggestion. I am quite sure the code is still wrong for what your need or there are better way to do it