Skip to content

Instantly share code, notes, and snippets.

@DrMabuse23
Created May 2, 2013 21:08
Show Gist options
  • Save DrMabuse23/5505482 to your computer and use it in GitHub Desktop.
Save DrMabuse23/5505482 to your computer and use it in GitHub Desktop.
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model=$this->loadModel($id);
if ($model->galleryBehavior->getGallery() === null) {
$gallery = new Gallery();
$gallery->name = true;
$gallery->description = true;
$gallery->save();
$model->gallery_id = $gallery->id;
$model->save();
}
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['BlogPost']))
{
$model->attributes=$_POST['BlogPost'];
$model->authorName = $_POST['BlogPost']['authorName'];
$model->categoryId = $_POST['BlogPost']['categoryId'];
if($model->save()){
$criteria = new CDbCriteria();
$criteria->compare('post_id',$model->id);
$lookup = BlogPostLookupCategory::model()->find($criteria);
if($model->categoryId != $lookup->category_id)
{
$lookup->category_id= $model->categoryId;
$lookup->update();
}
$this->redirect($this->homeUrl);
}
}
$this->render('update',array(
'model'=>$model,
));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment