发表文章时关联分类 
                            
                                                    
                        
                    
                    
  
                    
                    1.首先在articles/create.gohtml里增加选择分类

2.在articles_controller.go控制器修改store方法
func (ac *ArticlesController) Store(w http.ResponseWriter, r *http.Request) {
    // 1. 初始化数据
    currentUser := auth.User()
    categoryIDStr := r.PostFormValue("category_id")//接收分类id
    _article := article.Article{
        Title:      r.PostFormValue("title"),
        Body:       r.PostFormValue("body"),
        CategoryID: types.StringToUint64(categoryIDStr),//把id转为所需类型
        UserID:     currentUser.ID,
    }
.
.
.
}
至此文章关联分类完。
          
          
          
                关于 LearnKu
              
                    
                    
                    
 
推荐文章: