Example #1
0
 public function createAction()
 {
     $this->view->Title = "Quản lý sản phẩm";
     $this->view->headTitle($this->view->Title);
     if ($this->getRequest()->isPost()) {
         $request = $this->getRequest()->getParams();
         $error = $this->_checkForm($request);
         $Product = new Product();
         $Product->merge($request);
         if ($Product->trySave()) {
             $folder = $Product->id;
         }
         if ($_FILES['product_images']['name']) {
             $dirname = "uploads/" . $folder . "/";
             $upload = new My_Plugin_Upload();
             $error = $upload->uploadImageFile($_FILES['product_images'], 800, 600, 1024000, array("image/png", "image/jpg", "image/gif", "image/x-png", "image/jpeg"), $dirname);
             if (!$error) {
                 $filename = $upload->fileName;
             }
         }
         if ($_FILES) {
             $dir = "uploads/" . $Product->id . "/gallery/";
             $images = $this->_uploadFiles($dir);
         }
         if (count($error) == 0) {
             if ($filename != "") {
                 $Product->product_images = $filename;
             }
             $Product->save();
             $this->Member->log('Sản phẩm:' . $Product->product_name . '(' . $Product->id . ')', 'Tạo mới');
             My_Plugin_Libs::setSplash('Sản phẩm: <b>' . $Product->product_name . '</b> đã tạo thành công. ');
             $this->_redirect($this->_helper->url('index', 'product', 'admin'));
         }
         if (count($error)) {
             $this->view->error = $error;
         }
     }
 }