Exemple #1
0
 function save_tree()
 {
     // Allow only ajax calls
     if (!is_ajax()) {
         return show_404();
     }
     $this->load->model('categories_model');
     $list = $this->input->post('list');
     // Update db with order posted
     $i = 0;
     foreach ($list as $id => $parent_id) {
         $Category = new Categories_model();
         $node_info_array = array();
         $node_info_array['id'] = $id;
         $node_info_array['parent_id'] = $parent_id == 'root' ? 0 : $parent_id;
         $node_info_array['sort'] = $i;
         // Save Node
         $Category->from_array($node_info_array);
         $Category->save();
         $i++;
     }
     // Clear categories cache so updates will show on next page load
     $this->load->library('categories_library');
     $this->categories_library->clear_cache();
 }