php - Cgridview row update and version number increase -


i new in php & using yii framework.can 1 please me issue facing.i have grid view page update button.when update information of row in grid view works fine.but if mistake enter wrong entry , want update information should first check if there entry of data before.if there data entry before, version number increase id. , if there no data entry before there create new data new id.

here controller update action code:

    public function actionupdate($id) {     $model=new cvupload;     $updatemodel= new cvupload;     $model=$this->loadmodel($id);     $cvhistory=new cvhistory;        if(isset($_post['cvupload']))      {         $model_unchanged = $this->loadmodel($id);         $model_changed = $this->loadmodel($id);         $model->attributes=$_post['cvupload'];           $updatemodel->attributes=$_post['cvupload']         if ($model_unchanged->user_id == $_post['cvupload']['user_id'] && $model_unchanged->job_title_id == $_post['cvupload']['job_title_id'] && $model_unchanged->file_name == $_post['cvupload']['file_name']){              $this->redirect(array('view','id'=>$model_unchanged->cv_id));            }                      elseif($model_changed->user_id !== $_post['cvupload']['user_id'] && $model_changed->job_title_id !== $_post['cvupload']['job_title_id'] && $model_changed->file_name !== $_post['cvupload']['file_name'] && $model_changed->version_id !== $_post['cvupload']['version_id'])           {             $model_changed->save(false);             $criteria = new cdbcriteria();             $criteria->condition = "cv_id = $model_changed->cv_id , is_current = 'yes'";             $cvhistory = cvhistory::model()->find($criteria);             $cvhistory->is_current = 'no';             $cvhistory->status = 'inactive';             if($cvhistory->save(false))             {                     $new_cvhistory=new cvhistory;                  $new_cvhistory->cv_id  = $model_changed->cv_id;                 $new_cvhistory->user_id  = $model_changed->user_id;                 $new_cvhistory->job_title_id  = $model_changed->job_title_id;                 $new_cvhistory->cv_type  = $model_changed->cv_type;                 $new_cvhistory->version_id  = $cvhistory->version_id+1;                 $model_changed->version_id = $new_cvhistory->version_id ;                 $new_cvhistory->file_name  = $model_changed->file_name;                 $new_cvhistory->upload_date  = $model_changed->upload_date;                 $new_cvhistory->update_date  = new cdbexpression("now()");                 $model_changed->update_date = $new_cvhistory->update_date ;                  $new_cvhistory->status  = $model_changed->status;                 $new_cvhistory->is_current  = "yes";                 $new_cvhistory->save(false);                 $model_changed->save(false);                 if($new_cvhistory->save(false))$this->redirect(array('view','id'=>$model_changed->cv_id));             }           }                  elseif($model->save())// if         {             $criteria = new cdbcriteria();             $criteria->condition = "cv_id = $model->cv_id , is_current = 'yes'";             $cvhistory = cvhistory::model()->find($criteria);             $cvhistory->is_current = 'no';             $cvhistory->status = 'inactive';              if($cvhistory->save(false))             {                 $new_cvhistory=new cvhistory;                  $new_cvhistory->cv_id  = $model->cv_id;                 $new_cvhistory->user_id  = $model->user_id;                 $new_cvhistory->job_title_id  = $model->job_title_id;                 $new_cvhistory->cv_type  = $model->cv_type;                 $new_cvhistory->version_id  = $cvhistory->version_id+1;                 $model->version_id = $new_cvhistory->version_id ;                 $new_cvhistory->file_name  = $model->file_name;                 $new_cvhistory->upload_date  = $model->upload_date;                 $new_cvhistory->update_date  = new cdbexpression("now()");                 $model->update_date = $new_cvhistory->update_date ;                  $new_cvhistory->status  = $model->status;                 $new_cvhistory->is_current  = "yes";                 $new_cvhistory->save(false);                 $model->save(false);                 if($new_cvhistory->save(false))$this->redirect(array('view','id'=>$model->cv_id));              }          }        }      $this->render('update',array(         'model'=>$model,         'cvhistory'=>$cvhistory,      )); } 

can 1 give me solution problem facing.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -