Admin::deleteModel PHP Method

deleteModel() public method

Deletes the models for which an array of IDs has been posted.
public deleteModel ( )
    public function deleteModel()
    {
        $response = 1;
        if (Yii::app()->request->isPostRequest) {
            $post = Yii::app()->request->getPost($this->modelName);
            if (array_key_exists('id', $post) && is_array($post['id'])) {
                foreach ($post['id'] as $id) {
                    $model = $this->model->findByPk($id);
                    if (isset($model->active)) {
                        $model->active = 0;
                        if ($model && !$model->save()) {
                            $response = 0;
                        }
                    } else {
                        if ($model && !$model->delete()) {
                            $response = 0;
                        }
                    }
                }
            }
        }
        echo $response;
    }

Usage Example

 /**
  * Deletes rows for the model.
  */
 public function actionDelete()
 {
     $admin = new Admin(OphInBiometry_LensType_Lens::model(), $this);
     $admin->deleteModel();
 }
All Usage Examples Of Admin::deleteModel