예제 #1
0
 /**
  * Allows the user to make changes to an existing vendor
  * 
  * 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 vendor 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 vendor indicated via ID in the query string.  If no ID is given in the query string
  * or if a vendor matching that ID cannot be found in the database, the user will be redirected to the
  * vendor index.
  */
 public function actionEdit()
 {
     if (isset($_POST['model'])) {
         $model = vendors::model()->getByPK($_POST['model']['id']);
         $model->setAttributes($_POST['model']);
         if ($model->save()) {
             testProject::setAlert('The changes were saved successfully.', 'success');
         } else {
             testProject::setAlert('We\'re sorry but your changes were not saved.  Please try again.', 'danger');
         }
         $this->redirect('vendors/view/' . $model->id);
     } else {
         if (isset($_GET['value'])) {
             $model = vendors::model()->getByPK($_GET['value']);
             $this->render('edit', array('model' => $model));
         } else {
             $this->redirect('vendors/index');
         }
     }
 }
예제 #2
0
 /**
  * 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');
         }
     }
 }