Yii Framework Forum: Save As New - Yii Framework Forum

Jump to content

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

Save As New I want to add this button Rate Topic: -----

#1 User is offline   zitter 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 140
  • Joined: 14-July 09

Posted 28 April 2010 - 05:32 AM

Hi, I would like to insert a button like "Save as new" in my form. I mean, you can "Save" button and update record or, using "Save as new", create a new record based on values in the form (of course with validation!). The problem is that $model->save understands automagically if a record has to be inserted or updated in the table. So is there a way to force "Create" record even if we are in Update action?
Don't know if I'm clear, I hope I am :)

Ciao
Danilo
0

#2 User is offline   vamp 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 181
  • Joined: 30-January 09

Posted 28 April 2010 - 05:34 AM

View Postzitter, on 28 April 2010 - 05:32 AM, said:

Hi, I would like to insert a button like "Save as new" in my form. I mean, you can "Save" button and update record or, using "Save as new", create a new record based on values in the form (of course with validation!). The problem is that $model->save understands automagically if a record has to be inserted or updated in the table. So is there a way to force "Create" record even if we are in Update action?
Don't know if I'm clear, I hope I am :)

Ciao
Danilo



if($form->submitted('save-as-new')){
  $arModel->setIsNewRecord(true);
  $arModel->setPrimaryKey(null);
}
$arModel->save();

-Posted Image-
Thanks, you make me stronger!
1

#3 User is offline   zitter 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 140
  • Joined: 14-July 09

Posted 28 April 2010 - 12:01 PM

It worked with if($_POST['save-as-new']). Thanks!

P.S. I've added 1 point to your reputation, but of course I didn't it to make you weaker :P
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