Sunday, 15 June 2014

javascript - give two function in one button in Yii framework -



javascript - give two function in one button in Yii framework -

i have question yii framework, have problem submit button, want given 2 fungsi save , update in 1 submit button, can tell me how set function on form ?

<div class="row buttons"> <?php echo chtml::submitbutton($model->isnewrecord ? 'create' : 'save'); ?> </div>

i alter 'save' 'update' it's still have error primary key added, how can create 2 function update , save in 1 force button ?

public function actioncreate() { $model=new tbluasuts; // uncomment next line if ajax validation needed // $this->performajaxvalidation($model); if(isset($_post['tbluasuts'])) { $model->attributes=$_post['tbluasuts']; if($model->save()) $this->redirect(array('view','id'=>$model->nim_mhs)); } if(isset($_post['tbluasuts']) { $model->attributes=$_post['tbluasuts']; if($model->update()) $this->redirect(array('view','id'=>$model->nim_mhs)); } $this->render('update',array( 'model'=>$model, )); }

in form, can utilize :

<div class="row buttons"> <?php echo chtml::submitbutton($model->isnewrecord ? 'create' : 'update'); ?> </div>

as far processing different actions on backend code, there few options, example, :-

direct form different urls set (hidden) field (for illustration id) , parse that. use default action activeform, directs invoking action, illustration actioncreate(), or actionupdate()

in lite of updates, please extend controller per initial suggestion have action actionupdate()

the main difference between actioncreate(), or actionupdate() actions create action create new (empty) tbluasuts object, while update action populates tbluasuts object database.

public function actioncreate() { $model=new tbluasuts; ... ... things $model ... ... $model->save(); } public function actionupdate { // id of existing entry passed in url. illustration // ...http:// .... /update/id/10 // $model = tbluasuts::model()->findbypk($_get['id']); ... ... things $model ... ... $model->save(); }

javascript php button yii

No comments:

Post a Comment