Ejemplo n.º 1
0
 /**
  * 保存文章的时候,将详细内容存入到content表中
  * @return boolean
  */
 public function modifyArticle()
 {
     $request_data = $this->data;
     if (parent::save() !== false) {
         $data = array('article_id' => $request_data['id'], 'content' => I('post.content', '', false));
         if (M('ArticleContent')->save($data) !== false) {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * 完成商品的更新。
  * 由于需要修改多张表的数据,所以我们重写了save方法,完成了复杂逻辑。
  * @return boolean
  */
 public function save()
 {
     $request_data = $this->data;
     if (parent::save() === false) {
         $this->error = '商品保存失败';
         return false;
     }
     //商品详细描述的信息
     $data = array('content' => I('post.content', '', false), 'goods_id' => $request_data['id']);
     if (D('GoodsIntro')->save($data) === false) {
         $this->error = '商品详情保存失败';
         return false;
     }
     //将商品的相册图片保存到数据表中
     $gallery = array();
     foreach (I('post.path', '', false) as $path) {
         $gallery[] = array('goods_id' => $request_data['id'], 'path' => $path);
     }
     if (!empty($gallery)) {
         if (M('GoodsGallery')->addAll($gallery) === false) {
             $this->error = '商品相册保存失败';
             return false;
         }
     }
     //将关联文章保存到数据表中
     $articles = array();
     foreach (I('post.article_ids', '', false) as $path) {
         $articles[] = array('goods_id' => $request_data['id'], 'article_id' => $path);
     }
     $article_model = M('GoodsArticle');
     $article_model->where(array('goods_id' => $request_data['id']))->delete();
     if (!empty($articles)) {
         if ($article_model->addAll($articles) === false) {
             $this->error = '关联文章保存失败';
             return false;
         }
     }
     return true;
 }