package controllers

import (
	"github.com/astaxie/beego"
)

type BaseController struct {
	beego.Controller
}

// 设置模板
// 第一个参数模板，第二个参数为layout
func (c *BaseController) SetTpl(template ...string) {
	var tplName string
	layout := ""
	switch {
	case len(template) == 1:
		tplName = template[0]
	case len(template) == 2:
		tplName = template[0]
		layout = template[1]
	default:
		tplName = "index.tpl"
	}
	c.Layout = layout
	c.TplName = tplName
}

// 重定向
func (c *BaseController) Redirect302(url string) {
	c.Redirect(url, 302)
	c.StopRun()
}
