Пример #1
0
 /**
  * Add action for category controller
  */
 public function addAction()
 {
     // action body
     try {
         $translate = Zend_Registry::get('Zend_Translate');
         $frmCategory = new Contact_Form_Category();
         $frmCategory->setAction($this->_request->getBaseUrl() . "/contact/category/add");
         $this->view->frmCategory = $frmCategory;
         if ($this->getRequest()->isPost()) {
             if ($frmCategory->isValid($_POST)) {
                 $mdlCategory = new Contact_Model_Category();
                 $fileName = '';
                 if ($frmCategory->image->isUploaded()) {
                     $ext = end(explode('.', $frmCategory->image->getFileName()));
                     $frmCategory->image->addFilter('Rename', implode('_', array('cc', date('YmdHis'))) . '.' . $ext);
                     $frmCategory->image->receive();
                     $fileName = $frmCategory->image->getFileName(null, false);
                     chmod(DIR_MOD_CONTACT_IMG_UPLOADS . '/' . $fileName, 0755);
                     $thumb = Zend_Layout::getMvcInstance()->getView()->thumbnail(DIR_MOD_CONTACT_IMG_UPLOADS . '/' . $fileName, 70, 70, DIR_MOD_CONTACT_THUMB_UPLOADS . '/', DIR_MOD_CONTACT_THUMB_UPLOADS);
                     chmod($thumb, 0755);
                     #chmod(DIR_MOD_CONTACT_IMG_UPLOADS.'/'.$fileName, 0755);
                 }
                 $category = $mdlCategory->createRow($frmCategory->getValues());
                 $category->image = $fileName;
                 $category->save();
                 $this->_helper->flashMessenger->addMessage(array('type' => 'info', 'header' => '', 'message' => $translate->translate("LBL_ITEM_CREATED_SUCCESSFULLY")));
                 $this->_helper->redirector("listregistered", "category", "contact");
             }
         } else {
             $fields = array();
             foreach ($frmCategory->getElements() as $element) {
                 $fields[] = $element->getName();
             }
             $frmCategory->addDisplayGroup($fields, 'form', array('legend' => "CONTACT_ADD_CATEGORY"));
         }
     } catch (Exception $e) {
         $this->_helper->flashMessenger->addMessage(array('type' => 'error', 'header' => '', 'message' => $e->getMessage()));
         $this->_helper->redirector("listregistered", "category", "contact");
     }
     return;
 }