public function createAction()
 {
     if (!$this->request->isPost()) {
         return $this->forward("products/index");
     }
     $form = new ProductsForm();
     $product = new Products();
     $data = $this->request->getPost();
     if (!$form->isValid($data, $product)) {
         foreach ($form->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->forward("products/new");
     }
     if (!$product->save()) {
         foreach ($product->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->forward("products/new");
     }
     $form->clear();
     $this->flash->success("提交成功");
     return $this->forward("products/index");
 }
 /**
  * Saves current product in screen
  *
  * @param string $id
  */
 public function saveAction()
 {
     if (!$this->request->isPost()) {
         return $this->forward("products/index");
     }
     $id = $this->request->getPost("id", "int");
     $product = Products::findFirstById($id);
     if (!$product) {
         $this->flash->error("Product does not exist");
         return $this->forward("products/index");
     }
     $form = new ProductsForm();
     $this->view->form = $form;
     $data = $this->request->getPost();
     if (!$form->isValid($data, $product)) {
         foreach ($form->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->forward('products/edit/' . $id);
     }
     if ($product->save() == false) {
         foreach ($product->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->forward('products/edit/' . $id);
     }
     $form->clear();
     $this->flash->success("Product was updated successfully");
     return $this->forward("products/index");
 }