Esempio n. 1
0
 public static function save(Application_Model_O_Article $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;
 }
Esempio n. 2
0
 public function asyncajaxAction()
 {
     $this->getResponse()->setHeader('Content-Type', 'application/json');
     $this->_helper->viewRenderer->setNoRender(true);
     $this->_helper->layout()->disableLayout();
     $params = $this->_getAllParams();
     $article = new Application_Model_O_Article();
     $validate = new Yy_Validate_Value();
     if ($validate->isValid($params['id'])) {
         $article->setId($params['id']);
     } else {
         $article->setCtime(date('Y-m-d H:i:s'));
     }
     if ($validate->isValid($params['title'])) {
         $article->setTitle($params['title']);
     }
     if ($validate->isValid($params['content'])) {
         $article->setContent($params['content']);
     }
     if ($validate->isValid($params['sort'])) {
         $article->setSort($params['sort']);
     }
     if ($validate->isValid($params['type'])) {
         $article->setType($params['type']);
     }
     if ($validate->isValid($params['status'])) {
         $article->setStatus($params['status']);
     }
     try {
         $article->save();
         $id = $article->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_Article::updateImage($id, $img);
         }
         $url = '/article/view?id=' . $id;
         $this->redirect($url);
     } catch (Zend_Db_Exception $e) {
         //$this->redirect('/error');
         $this->redirect('/error?message=' . $e->getMessage());
     }
 }