/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Taxonomy();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Taxonomy'])) {
         $model->attributes = $_POST['Taxonomy'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 private function updateContentTypeAndTaxonomies($data)
 {
     foreach ($data['taxonomies'] as $taxonomy_id => $taxonomy) {
         if (array_key_exists('_destroy', $taxonomy) && $taxonomy['_destroy'] === 'on') {
             try {
                 Taxonomy::deleteTaxonomy((int) $taxonomy_id);
             } catch (Exception $e) {
                 new WP_Error(500, "Couldn't delete taxonomy");
                 exit;
             }
         } elseif (array_key_exists('name', $taxonomy) && strlen($taxonomy['name']) > 0) {
             $content_type = new Content_Type((int) $_POST['id']);
             $new_taxonomy = new Taxonomy($taxonomy['name'], $content_type);
             try {
                 $saved = $new_taxonomy->save();
             } catch (Exception $e) {
                 new WP_Error(500, "Couldn't save taxonomy in content type {$content_type->name}");
                 exit;
             }
             if (!$saved) {
                 $this->renderErrors($new_taxonomy->errors);
             }
             $this->content_types_admin_index();
         }
     }
 }