统一初始beego mvc 的方法
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.2 KiB

package mvc
import (
"github.com/astaxie/beego"
"golib.gaore.com/GaoreGo/beegoinit/response"
"strings"
)
type NestInterface interface {
NestPrepare()
}
type BaseController struct {
beego.Controller
}
func (this *BaseController) Prepare() {
sep := "/"
s := this.GetRouterSlice()
this.ViewPath = "applications/" + s[0] + sep + beego.AppConfig.String("customviewdir") + sep
this.TplName = s[1] + sep + s[2] + ".tpl"
if app, ok := this.AppController.(NestInterface); ok {
app.NestPrepare()
}
}
func (this *BaseController) RespJson(status bool, code int, msg string, data interface{}) {
this.Data["json"] = &response.Json{
Code: code,
Data: data,
Msg: msg,
Status: status,
}
this.ServeJSON()
}
func (this *BaseController) SetLayoutEmpty() {
this.Layout = ""
}
func (this *BaseController) StopRender() {
this.EnableRender = false
}
func (this *BaseController) GetRouterSlice() (s []string) {
sep := "/"
s = strings.Split(strings.Trim(this.Ctx.Input.URL(), sep), sep)
if s[0] == "" {
s[0] = strings.TrimSpace(strings.Split(beego.AppConfig.String("custommodules"), ",")[0])
}
if len(s) < 2 {
s = append(s, "main")
}
if len(s) < 3 {
s = append(s, "index")
}
return
}