當前位置: 首頁>>代碼示例>>Golang>>正文


Golang FocusCate.GetById方法代碼示例

本文整理匯總了Golang中github.com/blackmady/NoneCMS/app/models.FocusCate.GetById方法的典型用法代碼示例。如果您正苦於以下問題:Golang FocusCate.GetById方法的具體用法?Golang FocusCate.GetById怎麽用?Golang FocusCate.GetById使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/blackmady/NoneCMS/app/models.FocusCate的用法示例。


在下文中一共展示了FocusCate.GetById方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Add

//添加焦點圖
func (c Focus) Add(focus *models.Focus) revel.Result {

	if c.Request.Method == "GET" {

		title := "添加焦點圖--GoCMS管理係統"

		FocusCate := new(models.FocusCate)
		Cate_list := FocusCate.GetCateList()

		c.Render(title, Cate_list)
		return c.RenderTemplate("Content/Focus/Add.html")

	} else {

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

			focus.Cid = Cid

			focusCate := new(models.FocusCate)
			focusCate_info := focusCate.GetById(Cid)

			if focusCate_info.Id <= 0 {
				c.Flash.Error("焦點圖分類錯誤!")
				c.Flash.Out["url"] = "/Focus/Add/"
				return c.Redirect("/Message/")
			}

			//****************************************
			//圖片

			//判斷是否是係統的分隔符
			separator := "/"
			if os.IsPathSeparator('\\') {
				separator = "\\"
			} else {
				separator = "/"
			}

			//接收上傳文件
			imgFile, header, err := c.Request.FormFile("img")
			if err != nil {
				c.Flash.Error("圖片上傳錯誤!")
				c.Flash.Out["url"] = "/Focus/Add/"
				return c.Redirect("/Message/")
			}
			defer imgFile.Close()

			//讀取文件數據
			fileData, _ := ioutil.ReadAll(imgFile)

			if len(fileData) >= 1024*1024*2 {
				c.Flash.Error("你上傳大小為" + utils.FileSize(len(fileData)) + ",文件應小於2M!")
				c.Flash.Out["url"] = "/Focus/Add/"
				return c.Redirect("/Message/")
			}

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

			//上傳文件目錄
			upload_dir, _ := config_conf.String("upload", "upload.dir")
			//允許上傳的後綴名
			titlesuffix, _ := config_conf.String("upload", "upload.titlesuffix")

			//文件類型檢測
			if !strings.Contains(titlesuffix, path.Ext(header.Filename)) {
				c.Flash.Error("文件隻支持圖片!")
				c.Flash.Out["url"] = "/Focus/Add/"
				return c.Redirect("/Message/")
			}

			//前台網站調用目錄
			web_save_path := fmt.Sprintf("/%s/focus/%s", upload_dir, time.Now().Format("2006/01/02/"))

			//文件保存目錄
			save_path := fmt.Sprintf("%s/www/%s/focus/%s", basepath, upload_dir, time.Now().Format("2006/01/02/"))
			//字符串替換 /替換為係統分隔符
			save_path = strings.Replace(save_path, "/", separator, -1)

			//創建目錄
			err = os.MkdirAll(save_path, os.ModePerm)
			if err != nil {
				c.Flash.Error("創建目錄失敗!")
				c.Flash.Out["url"] = "/Focus/Add/"
				return c.Redirect("/Message/")
			}

			//新文件名
			rand.Seed(time.Now().UnixNano())
			rand_num := rand.Intn(99999)

//.........這裏部分代碼省略.........
開發者ID:blackmady,項目名稱:GoCMS,代碼行數:101,代碼來源:focus.go

示例2: Edit

//編輯分類
func (c FocusCate) Edit(focusCate *models.FocusCate) 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)
			}

			focusCate_info := focusCate.GetById(Id)

			c.Render(title, focusCate_info)
		} else {
			c.Render(title)
		}

		return c.RenderTemplate("Content/FocusCate/Edit.html")

	} else {

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

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

		var name string = c.Params.Get("name")
		if len(name) > 0 {
			focusCate.Name = name
		} else {
			c.Flash.Error("請輸入分類名稱!")
			c.Flash.Out["url"] = "/focusCate/edit/" + id + "/"
			return c.Redirect("/Message/")
		}

		var width string = c.Params.Get("width")
		if len(width) > 0 {
			Width, err := strconv.ParseInt(width, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}
			focusCate.Width = Width
		} else {
			c.Flash.Error("請輸寬度!")
			c.Flash.Out["url"] = "/focusCate/edit/" + id + "/"
			return c.Redirect("/Message/")
		}

		var height string = c.Params.Get("height")
		if len(height) > 0 {
			Height, err := strconv.ParseInt(height, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}
			focusCate.Height = Height
		} else {
			c.Flash.Error("請輸入高度!")
			c.Flash.Out["url"] = "/focusCate/edit/" + id + "/"
			return c.Redirect("/Message/")
		}

		if focusCate.Edit(Id) {
			c.Flash.Success("編輯分類成功")
			c.Flash.Out["url"] = "/FocusCate/"
			return c.Redirect("/Message/")
		} else {
			c.Flash.Error("編輯分類失敗!")
			c.Flash.Out["url"] = "/focusCate/edit/" + id + "/"
			return c.Redirect("/Message/")
		}

	}
}
開發者ID:blackmady,項目名稱:GoCMS,代碼行數:80,代碼來源:focuscate.go


注:本文中的github.com/blackmady/NoneCMS/app/models.FocusCate.GetById方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。