public function update()
 {
     $category = new Cat($this->db);
     if ($this->f3->exists('POST.update')) {
         $uurl = toUrl($this->f3->get('POST.name'));
         //check if the category already exists
         //if not unique name
         $uname = new Cat($this->db);
         if ($uname->catcountByUrl($uurl) > 0) {
             $this->f3->set('COOKIE.message', 'The category name already exists!');
             $this->f3->set('COOKIE.messagetype', 'alert-danger hide10s');
             $this->f3->reroute('/c/update/' . $this->f3->get('POST.tok'));
         }
         $this->f3->set('POST.url', toUrl($this->f3->get('POST.name')));
         $this->f3->set('POST.name', preg_replace('|[^0-9A-Za-z\\-\\/+]|', '', $this->f3->get('POST.name')));
         $category->edit($this->f3->get('POST.tok'));
         $this->f3->set('COOKIE.message', 'Category has been successfully saved!');
         $this->f3->set('COOKIE.messagetype', 'alert-success hide5s');
         $this->f3->reroute('/c');
     } else {
         $category->getById($this->f3->get('PARAMS.tok'));
         $this->f3->set('categoires', $category);
         $this->f3->set('header', 'Update Category');
         $this->f3->set('view', 'cats/update.htm');
         //menu
         $this->f3->set('topmenu', 'c');
         //breadcrumbs
         $this->f3->set('breadcrumb', array(array("url" => "/c", "name" => "Categories"), array("url" => NULL, "name" => "Update Category")));
     }
     //display messages (if not empty) and clear values
     if ($this->f3->get('COOKIE.message')) {
         $this->f3->set('message', $this->f3->get('COOKIE.message'));
         $this->f3->set('COOKIE.message', '');
     }
     if ($this->f3->get('COOKIE.messagetype')) {
         $this->f3->set('messagetype', $this->f3->get('COOKIE.messagetype'));
         $this->f3->set('COOKIE.messagetype', '');
     }
 }