Adderror In Beforesave Not Work When $Model->Save() In Loop

while insert multiple data, then $this->addError stop working.

for example in Controller:




foreach($roomfacilty as $data)

			{

		        $model->setIsNewRecord(true);

			$model->hostel_room_category_facility_id=null;

			$model->hostel_room_category_id=$_POST['HostelRoomCategoryFacility']['hostel_room_category_id'];

			$model->hostel_room_facility_id = $data;		

            		$model->hostel_room_category_facility_creation_date = new CDbExpression('NOW()');

			$model->save();			

			}



when as above data insert then it check validation properly in beforeSave() but not give error message(which is display through addError).

Thanks

There is no problem regarding addError. But main problem is redirection.

Please use following tips:

$var = $model->save();

you store value of $model->save(); in $var. And if it return true then redirect otherwise render your _form view.

Thankx.

Regards

Ravi Bhalodiya.

RudraSoftech Team

Thanks its solve my problem.:slight_smile:

[color="#006400"]/* moved from Bug Discussions */[/color]