Creating default object from empty value

I was trying to upload students in my application, and then it will call a function

getUniqueId()

to create a uniqueiD

[b]

$insMaster->instructor_unique_id = $insMaster->getUniqueId();

[/b]




	public function importInsData($model)

	{

		$dispResults = []; 

		$totalSuccess = 0;

		

		$objPHPExcel = PHPExcel_IOFactory::load($model->importFilePath.$model->importFile);

		$sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);

		

		//print_r($sheetData); exit;

		unset($sheetData[1]);


		//start import student row by row

		foreach($sheetData as $k => $line){

			//print_r($line); exit;

			if(!array_filter($line))

				continue;

				 

			$line = array_map('trim', $line);

			$line = array_map(function($value) { return empty($value) ? NULL : $value; }, $line);

			

			$insMaster = new Instructors();

			$insMaster->scenario = 'import-ins';

			$user = new User();		

			$auth_assign = new AuthAssignment();


			//set instructor info attributes

			$insMaster->instructor_unique_id = $insMaster->getUniqueId();	// Student Unique Id

			$insMaster->first_name = $line['A']; //First Name

			$insMaster->last_name = $line['B']; //Last Name 

                        $insMaster->gender = $this->valueReplace($line['C'], $stuInfo->getGenderOptions()); // Gender

                        $insMaster->email = $line['D']; // Email ID

                        $insMaster->phone1 = $line['E']; //Mobile No

                        $insMaster->country_id = $this->valueReplace($line['F'], Countries::getAllCountry()); //Country

                        $user->user_login_id = $line['G']; //Username

                        $user->user_login_id = md5($line['H'].$line['H']); //Password                      

			$insMaster->middle_name = $line['I']; // Email ID

			$insMaster->phone2 = $line['J']; // Mobile No

			$insMaster->address = $line['K']; // Email ID

			$insMaster->city = $line['L']; // Mobile No                        

			

	

			//set user login info attributes

			$uniq_id = $stuInfo->getUniqueId();

			$login_id = \app\models\Organization::find()->one()->org_stu_prefix.$uniq_id;


			$user->user_type = "I"; //user type

			$user->created_by = Yii::$app->getid->getId();	//created by		

			$user->created_at = new \yii\db\Expression('NOW()'); //created at


			if($user->validate())

			{				

				$transaction = Yii::$app->db->beginTransaction();

				try{

					if($user->save()){

						

						$insMaster->user_id = $user->user_id;	

                                                $insMaster->auth = 'manual';

						$insMaster->created_by = Yii::$app->getid->getId();

						$insMaster->created_at = new \yii\db\Expression('NOW()');

						if($insMaster->save()){


								$auth_assign->item_name = 'Instructor';

								$auth_assign->user_id = $user->user_id;

								$auth_assign->created_at = date_format(date_create(),'U');

								$auth_assign->save(false);

								$transaction->commit();

								$totalSuccess+=1;

								$dispResults[] = array_merge($line, ['type' => 'I', 'instructorId' => $insMaster->instructor_id, 'message' => 'Success']);

						}else{

							$dispResults[] = array_merge($line, ['type' => 'E', 'message' => Html::errorSummary($insMaster)]);							

						}

					} // end stuInfo, user, StuAddress

					$transaction->rollback();

				}

				catch(\Exception $e){

					$transaction->rollBack();

					$dispResults[] = array_merge($line, ['type' => 'E', 'message' => $e->getMessage()]);

				}					

			}else{

				$dispResults[] = array_merge($line, [

						'type' => 'E', 

						'message' => Html::errorSummary([$user,  $insMaster]),

					]);

			}  //end validated if	

		} //end foreach

		return ['dispResults' => $dispResults, 'totalSuccess' => $totalSuccess];

	}



But I got this error

7616

defaulterror.PNG

from

[code]

public function getUniqueId()


{


	$ins_uniq_no = \app\modules\instructor\models\Instructors::find()->max('instructor_unique_id');


	$uniq_id = NULL;


	if(empty($ins_uniq_no)) {


		$uniq_id = $model->instructor_unique_id = 1;


	}


	else {


		$chk_id = Instructors::find()->where(['instructor_unique_id' => $ins_uniq_no])->exists(); 


		if($chk_id)


			$uniq_id = $ins_uniq_no + 1;


		else


			$uniq_id = $ins_uniq_no;		


	}


	


	return $uniq_id;


}  

[/code

How do I resolve it

Where do you get $model from? Shouldn’t that be (probably) $this ?

P.S.: next time try to show only the relevant piece of code, I got lost reading all the stuff you posted above - in addition to this you didn’t correctly format the last piece of code you posted… :)