public static function save(Application_Model_O_DepartmentsAdditional $obj, $extra = '')
 {
     if (!$obj->getModifiedFields()) {
         return $obj;
     }
     foreach ($obj->getModifiedFields() as $key => $value) {
         $field = self::$fields[strtolower($key)];
         if ($field) {
             $data[$field] = $value;
         }
     }
     if (!$obj->getId()) {
         $obj->setId(self::getDbTable()->insert($data, $extra));
         $obj->setNew(false);
     } else {
         self::getDbTable()->update($data, array('id = ?' => $obj->getId()));
     }
     return $obj;
 }
 public function addiasyncajaxAction()
 {
     $this->getResponse()->setHeader('Content-Type', 'application/json');
     $this->_helper->viewRenderer->setNoRender(true);
     $this->_helper->layout()->disableLayout();
     $params = $this->_getAllParams();
     $hmsg = $this->_getParam('hmsg');
     //    	echo "<pre>";var_dump($params);exit;
     $addi = new Application_Model_O_DepartmentsAdditional();
     $validate = new Yy_Validate_Value();
     if ($validate->isValid($params['id'])) {
         $addi->setId($params['id']);
     } else {
         $addi->setCtime(date('Y-m-d H:i:s'));
     }
     if ($validate->isValid($params['did'])) {
         $addi->setDepartment_id($params['did']);
     }
     if ($validate->isValid($params['title'])) {
         $addi->setTitle($params['title']);
     }
     if ($validate->isValid($params['content'])) {
         $addi->setContent($params['content']);
     }
     if ($validate->isValid($params['sort'])) {
         $addi->setSort($params['sort']);
     }
     if ($validate->isValid($params['type'])) {
         $addi->setType($params['type']);
     }
     if ($validate->isValid($params['status'])) {
         $addi->setStatus($params['status']);
     }
     try {
         $addi->save();
         $id = $addi->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_DepartmentsAdditional::updateImage($id, $img);
         }
         $url = '/costperf/addiview?id=' . $id . '&from=add&did=' . $params['did'] . '&hmsg=' . $hmsg;
         $this->redirect($url);
     } catch (Zend_Db_Exception $e) {
         $this->redirect('/error?message=' . $e->getMessage());
     }
 }