最新消息: 新版网站上线了!!!

Create custom button with AJAX function in CGridView

Create custom button with AJAX function in CGridView

 

First we need to create the required action in our controller, we will call it simply ‘status’.  To begin we add it in our controller rules ‘actions’ array:
array('allow'
      'actions'=>array('view''update', 'delete', 'status')),
      'users'=>array('admin'),
),
 
Next we need to create an action for setting our record status:
 

public function actionStatus($id)

{
    $model = MyModel::model()->findByPk($id);  // use whatever the correct class name is
    $model->status = ($model->status ==1 ? 1 : 0);
    $model->save();
 
    return true;
 



Now we are ready to create our custom button.  If you look at a standard Yii generated cGridview, toward the bottom you

转载请注明:谷谷点程序 » Create custom button with AJAX function in CGridView