public function saveblogAction() { global $mySession; $db = new Db(); if ($this->getRequest()->isPost()) { $request = $this->getRequest(); $myform = new Form_Blog(); if ($myform->isValid($request->getPost())) { $dataform = $myform->getValues(); $blogdata['title'] = $dataform['title']; $blogdata['description'] = $dataform['description']; $blogdata['status'] = 1; $blogdata['cr_date'] = date("Y-m-d H:i:s"); $blogdata['activeBlog'] = 1; $db->save(BLOG_POST, $blogdata); $this->_redirect('blog/index'); } else { $this->view->myform = $myform; $this->render('addblog'); } } else { $this->_redirect('blog/index'); } }
public function updateAction() { $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $this->identity = $auth->getIdentity(); } if (!$this->identity->id) { $this->_redirect('/user/login'); } $id = $this->_request->getParam('id'); $modelBlog = new Page(); $formBlog = new Form_Blog(); if ($this->getRequest()->isPost()) { if ($formBlog->isValid($_POST)) { $blogData = $formBlog->getValues(); $blogData['uid'] = $this->identity->id; $blogData['type'] = 'now'; $blogData['createtime'] = time(); $tags = str_replace(",", ",", $blogData['tags']); unset($blogData['tags']); unset($blogData['提交']); $updateBlog = $modelBlog->updatePage($id, $blogData); if ($updateBlog) { if ($tags != null) { $modelTags = new Tags(); $modelTags->deleteTags($id); // 清空原tags $modelTags->createTags($updateBlog, $tags); $modelTagsTotal = new TagsTotal(); $arrTags = explode(",", $tags); if (count($arrTags) > 0) { foreach ($arrTags as $value) { $modelTagsTotal->cutTag($value); // 从total中减去 $modelTagsTotal->createTag($value); //重新创建 } } else { $modelTagsTotal->createTag($tags); } } $this->_redirect('blog/view/id/' . $updateBlog); } } } else { $blog = $modelBlog->getPage($id); if ($this->identity->id != $blog->uid) { echo "你不是本博客的作者,不能对本博客进行编辑操作。"; exit; } $arrBlog = $blog->toArray(); // 该blog的tags $modelTags = new Tags(); $where = array('blog_id' => $id); $tags = $modelTags->getTags($where); if (count($tags) > 0) { $strTags = ''; foreach ($tags as $tag) { $strTags .= $tag->tag . ","; } $strTags = rtrim($strTags, ","); } $arrBlog['tags'] = $strTags; $formBlog->populate($arrBlog); } $this->view->formBlog = $formBlog; // $this->_helper->cache(array('index', 'view'), array('gook')); }