发表文章时关联分类

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,
    }

.
.
.
}

至此文章关联分类完。

于江
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!