Skip to content Skip to sidebar Skip to footer

Give Two Function In One Button In Yii Framework

I have a question about Yii framework, i have problem with submit button, i want to given two fungsi save and update in one submit button, can anyone tell me how to set that functi

Solution 1:

In your form, you can use something like :

<divclass="row buttons"><?phpecho CHtml::submitButton($model->isNewRecord ? 'Create' : 'Update'); ?></div>

As far as processing different actions on the backend code, there are a few options, for example, you could :-

  • Direct your form to different URLs
  • Set a (hidden) field (for example ID) and parse for that.
  • Use the default action from the activeForm, which directs back to the invoking action, for example actionCreate(), or actionUpdate()

In light of your updates, please extend your controller as per my initial suggestion to have another action actionUpdate()

The main difference between the actionCreate(), or actionUpdate() actions is that the Create action create a new (empty) TblUasUts object, while the Update action populates the TblUasUts object from the database.

publicfunctionactionCreate()
{
    $model=new TblUasUts;
    ...
    ... Do things with $model ...
    ...
    $model->save();

}

publicfunctionactionUpdate{
    // The id of the existing entry is passed in the url. for example// ...http:// .... /update/id/10//$model = TblUasUts::model()->findByPK($_GET['id']);
    ...
    ... Do things with $model ...
    ...
    $model->save();

}

Post a Comment for "Give Two Function In One Button In Yii Framework"