当前位置: 首页>>代码示例>>Golang>>正文


Golang Category.GetById方法代码示例

本文整理汇总了Golang中admin/app/models.Category.GetById方法的典型用法代码示例。如果您正苦于以下问题:Golang Category.GetById方法的具体用法?Golang Category.GetById怎么用?Golang Category.GetById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在admin/app/models.Category的用法示例。


在下文中一共展示了Category.GetById方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Edit

//编辑内容
func (c Content) Edit(article *models.Article) revel.Result {

	if c.Request.Method == "GET" {
		title := "内容--GoCMS编辑内容"

		var cid string = c.Params.Get("cid")
		var id string = c.Params.Get("id")

		if len(cid) > 0 {

			Cid, err := strconv.ParseInt(cid, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			Id, err := strconv.ParseInt(id, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			//内容
			article_info := article.GetById(Id)

			//栏目信息
			category := new(models.Category)
			category_info := category.GetById(Cid)

			//来源
			copyfrom := new(models.Copyfrom)
			copyfrom_list := copyfrom.GetRoleList()

			c.Render(title, cid, category_info, article_info, copyfrom_list)
			return c.RenderTemplate("Content/Manage/Edit.html")
		} else {
			c.Render(title, cid)
			return c.RenderTemplate("Content/Manage/Edit.html")
		}

	} else {

		var dosubmit string = c.Params.Get("dosubmit")
		var dosubmit_continue string = c.Params.Get("dosubmit_continue")

		var cid string = c.Params.Get("cid")
		var id string = c.Params.Get("id")

		Id, err := strconv.ParseInt(id, 10, 64)
		if err != nil {
			revel.WARN.Println(err)
		}

		var title string = c.Params.Get("title")
		if len(title) > 0 {
			article.Title = title
		} else {
			c.Flash.Error("请输入标题!")
			c.Flash.Out["url"] = "/Content/Add/" + cid + "/"
			return c.Redirect("/Message/")
		}

		var style_color string = c.Params.Get("style_color")
		article.Color = style_color
		var style_font_weight string = c.Params.Get("style_font_weight")
		article.Font = style_font_weight

		var thumb string = c.Params.Get("thumb")
		if len(thumb) > 0 {

			//判断是否是系统的分隔符
			separator := "/"
			if os.IsPathSeparator('\\') {
				separator = "\\"
			} else {
				separator = "/"
			}

			config_file := (revel.BasePath + "/conf/config.conf")
			config_file = strings.Replace(config_file, "/", separator, -1)
			config_conf, _ := config.ReadDefault(config_file)

			//前台网站地址
			sitedomain, _ := config_conf.String("website", "website.sitedomain")
			thumb = strings.Replace(thumb, sitedomain, "", -1)

			article.Thumb = thumb
		} else {
			article.Thumb = ""
		}

		var content string = c.Params.Get("content")
		if len(content) > 0 {
			article.Content = content
		} else {
			c.Flash.Error("请输入内容!")
			c.Flash.Out["url"] = "/Content/Add/" + cid + "/"
			return c.Redirect("/Message/")
		}

		var copyfrom string = c.Params.Get("copyfrom")
//.........这里部分代码省略.........
开发者ID:zacklin923,项目名称:GoCMS,代码行数:101,代码来源:content.go

示例2: Edit

//编辑栏目
func (c Category) Edit(category *models.Category) revel.Result {

	if c.Request.Method == "GET" {
		title := "编辑栏目--GoCMS管理系统"

		var id string = c.Params.Get("id")
		if len(id) > 0 {
			Id, err := strconv.ParseInt(id, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			//获取菜单信息
			category_info := category.GetById(Id)

			//返回菜单Option的HTML
			categorys := category.GetCateGoryOptionHtml(category_info.Pid)

			c.Render(title, categorys, category_info)
		} else {

			//返回菜单Option的HTML
			categorys := category.GetCateGoryOptionHtml(0)

			c.Render(title, categorys)
		}

		return c.RenderTemplate("Content/Category/Edit.html")
	} else {
		var id string = c.Params.Get("id")

		if len(id) > 0 {
			Id, err := strconv.ParseInt(id, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			//栏目类型
			var cate_type string = c.Params.Get("type")
			if len(cate_type) > 0 {
				Type, err := strconv.ParseInt(cate_type, 10, 64)
				if err != nil {
					revel.WARN.Println(err)
				}
				category.Type = Type
			} else {
				c.Flash.Error("请选择栏目类型!")
				c.Flash.Out["url"] = "/Category/Edit/" + id + "/"
				return c.Redirect("/Message/")
			}

			//上级栏目
			var pid string = c.Params.Get("pid")
			if len(pid) > 0 {
				Pid, err := strconv.ParseInt(pid, 10, 64)
				if err != nil {
					revel.WARN.Println(err)
				}
				category.Pid = Pid
			} else {
				c.Flash.Error("请选择父栏目!")
				c.Flash.Out["url"] = "/Category/Edit/" + id + "/"
				return c.Redirect("/Message/")
			}

			//栏目名称
			var name string = c.Params.Get("name")
			if len(name) > 0 {
				category.Name = name
			} else {
				c.Flash.Error("请输入栏目名称!")
				c.Flash.Out["url"] = "/Category/Edit/" + id + "/"
				return c.Redirect("/Message/")
			}

			var enname string = c.Params.Get("enname")
			if len(enname) > 0 {
				category.Enname = enname
			} else {
				c.Flash.Error("请输入英文栏目名称!")
				c.Flash.Out["url"] = "/Category/Edit/" + id + "/"
				return c.Redirect("/Message/")
			}

			//栏目地址
			var url string = c.Params.Get("url")
			if len(url) > 0 {
				category.Url = url
			} else {
				c.Flash.Error("请输入栏目地址!")
				c.Flash.Out["url"] = "/Category/Edit/" + id + "/"
				return c.Redirect("/Message/")
			}

			//描述
			var desc string = c.Params.Get("desc")
			if len(desc) > 0 {
				category.Desc = desc
			} else {
//.........这里部分代码省略.........
开发者ID:JREAMLU,项目名称:GoCMS,代码行数:101,代码来源:category.go

示例3: AddContent

//单页面 添加内容
func (c Content) AddContent(article *models.Article) revel.Result {
	if c.Request.Method == "GET" {
		title := "内容--GoCMS添加内容"

		var cid string = c.Params.Get("cid")

		if len(cid) > 0 {

			Cid, err := strconv.ParseInt(cid, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			//栏目信息
			category := new(models.Category)
			category_info := category.GetById(Cid)

			//内容
			article_info := article.GetByCid(Cid)

			c.Render(title, cid, category_info, article_info)
			return c.RenderTemplate("Content/Manage/AddContent.html")
		} else {
			c.Render(title, cid)
			return c.RenderTemplate("Content/Manage/AddContent.html")
		}
	} else {

		var cid string = c.Params.Get("cid")

		if len(cid) < 0 {
			c.Flash.Error("请选择栏目!")
			c.Flash.Out["url"] = "/Content/addContent/" + cid + "/"
			return c.Redirect("/Message/")
		}

		UserID := utils.GetSession("UserID", c.Session)

		if len(UserID) > 0 {
			UserID, err := strconv.ParseInt(UserID, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}
			article.Aid = UserID
		}

		var title string = c.Params.Get("title")
		if len(title) > 0 {
			article.Title = title
		} else {
			c.Flash.Error("请输入标题!")
			c.Flash.Out["url"] = "/Content/addContent/" + cid + "/"
			return c.Redirect("/Message/")
		}

		var style_color string = c.Params.Get("style_color")
		article.Color = style_color
		var style_font_weight string = c.Params.Get("style_font_weight")
		article.Font = style_font_weight

		var keywords string = c.Params.Get("keywords")
		if len(keywords) > 0 {
			article.Keywords = keywords
		} else {
			article.Keywords = ""
		}

		var content string = c.Params.Get("content")
		if len(content) > 0 {
			article.Content = content
		} else {
			c.Flash.Error("请输入内容!")
			c.Flash.Out["url"] = "/Content/addContent/" + cid + "/"
			return c.Redirect("/Message/")
		}

		if len(cid) > 0 {

			Cid, err := strconv.ParseInt(cid, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			article.Cid = Cid

			//内容
			article_info := article.GetByCid(Cid)

			if article_info.Id > 0 {
				if article.Edit(article_info.Id) {
					c.Flash.Success("编辑内容成功!")
					c.Flash.Out["url"] = "/Content/addContent/" + cid + "/"
					return c.Redirect("/Message/")
				} else {
					c.Flash.Success("编辑内容成功!")
					c.Flash.Out["url"] = "/Content/addContent/" + cid + "/"
					return c.Redirect("/Message/")
				}
			} else {
//.........这里部分代码省略.........
开发者ID:zacklin923,项目名称:GoCMS,代码行数:101,代码来源:content.go


注:本文中的admin/app/models.Category.GetById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。