CategoryModel::saveSubtree PHP Method

saveSubtree() public method

Save a subtree.
public saveSubtree ( array $subtree, $parentID )
$subtree array A nested array where each array contains a CategoryID and optional Children element.
    public function saveSubtree($subtree, $parentID)
    {
        $this->saveSubtreeInternal($subtree, $parentID);
    }

Usage Example

 /**
  * Sorting display order of categories.
  */
 public function categoriesTree()
 {
     // Check permission
     $this->permission(['Garden.Community.Manage', 'Garden.Settings.Manage'], false);
     if ($this->Request->isAuthenticatedPostBack(true)) {
         $tree = json_decode($this->Request->post('Subtree'), true);
         $this->CategoryModel->saveSubtree($tree, $this->Request->post('ParentID', -1));
         $this->setData('Result', count($this->CategoryModel->Validation->results()) === 0);
         $this->setData('Validation', $this->CategoryModel->Validation->resultsArray());
     } else {
         throw new Gdn_UserException($this->Request->requestMethod() . ' is not allowed.', 405);
     }
     // Renders true/false rather than template
     $this->render();
 }