/** * Allows the user to make changes to an existing category * * If data has been posted, an attempt will be made to save the changes to the database. The user * will then be redirected to the category view with a notification whether the changes were saved * or not. If no data has been posted, the method will attempt to render a form with the editable * fields for the category indicated via ID in the query string. If no ID is given in the query string * or if a category matching that ID cannot be found in the database, the user will be redirected to the * category index. */ public function actionEdit() { if (isset($_POST['model'])) { if ($model = statuses::model()->getByPK($_POST['model']['id'])) { } else { testProject::setAlert('The requested item does not exist or you do not have permission to view it. Please try again.', 'warning'); $this->redirect('statuses/index'); } $model->setAttributes($_POST['model']); if ($model->save()) { testProject::setAlert('The changes were saved successfully.', 'success'); } else { testProject::setAlert("Your changes could not be saved. Please try again.", 'danger'); } $this->redirect('statuses/view/' . $model->id); } else { if (isset($_GET['value'])) { if ($model = statuses::model()->getByPK($_GET['value'])) { $this->render('edit', array('model' => $model)); } else { testProject::setAlert('The requested item does not exist or you do not have permission to view it. Please try again.', 'warning'); $this->redirect('statuses/index'); } } else { $this->redirect('statuses/index'); } } }
/** * Allows the user to make changes to an existing product * * If data has been posted, an attempt will be made to save the changes to the database. The user * will then be redirected to the product view with a notification whether the changes were saved * or not. If no data has been posted, the method will attempt to render a form with the editable * fields for the product indicated via ID in the query string. If no ID is given in the query string * or if a product matching that ID cannot be found in the database, the user will be redirected to the * product index. */ public function actionEdit() { if (isset($_POST['model'])) { //check that data has been posted $model = items::model()->getByPK($_POST['model']['id']); $model->setAttributes($_POST['model']); if ($model->save()) { //set the alert based on success of the save testProject::setAlert('The changes were saved successfully.', 'success'); $this->redirect("items/view/{$model->id}"); } else { testProject::setAlert('We\'re sorry but your changes were not saved. Please try again.', 'danger'); $this->redirect("items/view/{$model->id}"); } //redirect to product view $this->redirect('items/view/' . $model->id); } else { //if no data is posted if (isset($_GET['value'])) { //attempt to load record based on ID and render edit form $model = items::model()->getByPK($_GET['value']); $statuses = statuses::model()->getAll(); $vendors = vendors::model()->getAll(); $tags = tags::model()->getAll(); $this->render('edit', array('model' => $model, 'statuses' => $statuses, 'vendors' => $vendors, 'tags' => $tags)); } else { //if no record found, redirect to product index $this->redirect('items'); } } }