Save Model


(Javi Hunzai) #1

hi

I need to save model from another controller. I used following code but it is not saving changes in database.




class FeePaidBulkController extends Controller

{

...

public function actionDoBulkPayment() {

 FeePaid::model()->student_id=$iStudentId;

 FeePaid::model()->fee_structure_id=$iFeeStructureId;

 if(FeePaid::model()->save())	{

 }

}

...

}


class FeepaidController extends Controller

{

....

}




(Alirz23) #2

create a new instance of the FeePaid like so


<?php


class FeePaidBulkController extends Controller

{

	public function actionDoBulkPayment() {

		$feePaid = new FeePaid;

		$feePaid->student_id=$iStudentId;

		$feePaid->fee_structure_id=$iFeeStructureId;

		if($feePaid->save()){

			// do stuff ...

		}

 	}


}


(Javi Hunzai) #3

Thanks alirz23. I was not creating instance of model thats why it was not saving in db.