Yii Framework Forum: Adderror In Beforesave Not Work When $Model->Save() In Loop - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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

#1 User is offline   hiral darji 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 31-May 12
  • Location:Ahmedabad

Posted 03 April 2013 - 07:22 AM

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
3

#2 User is offline   Ravi Bhalodiya 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 64
  • Joined: 27-August 12
  • Location:Gujarat India

Posted 06 April 2013 - 01:47 AM

View Posthiral darji, on 03 April 2013 - 07:22 AM, said:

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
Regards
Ravi Bhalodiya.
4

#3 User is offline   hiral darji 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 31-May 12
  • Location:Ahmedabad

Posted 06 April 2013 - 02:44 AM

View PostRavi Bhalodiya, on 06 April 2013 - 01:47 AM, said:

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.:-)
0

#4 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 06 April 2013 - 08:18 AM

/* moved from Bug Discussions */
"Less noise - more signal"
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users