protected function saveAction($id = 0)
	{
		if ($id)
		{
			$action = 'edit';
			$category = Categories::findFirst($id);
			
	        if (!$category) 
	        {
	            $this->flash->error("Element not found");
	            return $this->forward("categories/index");
	        }
		}
		else 
		{
			$action = 'new';
			$category = new Categories;
		}
		
		$form = new CategoriesForm;
		
        $data = $this->request->getPost();
		
        if (!$form->isValid($data, $category)) 
        {
            foreach ($form->getMessages() as $message) 
            {
                $this->flash->error($message);
            }
            return $this->forward('categories/' . $action);
        }

        if ($category->save() == false) 
        {
            foreach ($category->getMessages() as $message) 
            {
                $this->flash->error($message);
            }
            return $this->forward('categories/' . $action);
        }

        $form->clear();

        $this->flash->success("Элемент успешно сохранен");
        return $this->forward("categories/index");		
	}
 public function CategoriesForm()
 {
     $form = new CategoriesForm($this, "CategoriesForm");
     $form->addExtraClass('cms-edit-form cms-panel-padded center ' . $this->BaseCSSClasses());
     return $form;
 }