public function cateasyncajaxAction()
 {
     $this->getResponse()->setHeader('Content-Type', 'application/json');
     $this->_helper->viewRenderer->setNoRender(true);
     $this->_helper->layout()->disableLayout();
     $params = $this->_getAllParams();
     $cate = new Application_Model_O_DepartmentsCategory();
     $validate = new Yy_Validate_Value();
     if ($validate->isValid($params['id'])) {
         $cate->setId($params['id']);
     } else {
         $cate->setCtime(date('Y-m-d H:i:s'));
     }
     if ($validate->isValid($params['name'])) {
         $cate->setName($params['name']);
     }
     if ($validate->isValid($params['sort'])) {
         $cate->setSort($params['sort']);
     }
     if ($validate->isValid($params['status'])) {
         $cate->setStatus($params['status']);
     }
     try {
         $cate->save();
         $id = $cate->getId();
         //保存行程图片
         $adapter = new Zend_File_Transfer_Adapter_Http();
         $wrdir = Yy_Utils::getWriteDir();
         $adapter->setDestination($wrdir);
         if (!$adapter->receive()) {
             $messages = $adapter->getMessages();
             //echo implode("\n", $messages);
         }
         $filename = $adapter->getFileName();
         if (is_string($filename)) {
             $handle = fopen($filename, 'rb');
             $img = addslashes(fread($handle, filesize($filename)));
             fclose($handle);
             Application_Model_M_DepartmentsCategory::updateImage($id, $img);
         }
         $url = '/costperf/cateview?id=' . $id . '&from=add';
         $this->redirect($url);
     } catch (Zend_Db_Exception $e) {
         $this->redirect('/error?message=' . $e->getMessage());
     }
 }
 public function delete()
 {
     $where = 'id=' . $this->getId();
     return Application_Model_M_DepartmentsCategory::delete($where);
 }
示例#3
0
 public static function getAllCategory()
 {
     $cates = Application_Model_M_DepartmentsCategory::fetchIdAndName();
     return $cates;
 }